问题
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