counting total objects in JSON Response

我们两清 提交于 2019-12-13 05:52:33

问题


I want to count the number of objects from this Response. I dont wnat to make classes for such a small purpose and then iterating over the classes. Is there any shorter way to do that.

I am using both JSON.NET and web.Serialization.


回答1:


This would return count of immediate objects in an array.

var input = "[{Name: 'Hello'}, {Name: 'Hi'}]";
dynamic response = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<dynamic>(input);
Response.Write(response.Length);


来源:https://stackoverflow.com/questions/11373749/counting-total-objects-in-json-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!