I have a JSON string below:
{
"data": [
{
//data for first
},
{
//data for second
},
{
//data for third
},
]
}
From this JSON string, I would like to retrieve the number of objects within the "data" element, which in this case, would be 3.
What would be the best approach to accomplish this? I used the .Length property, but that returned a number that I did not expect.
I am using C#.
Since it’s a string in C# you need to parse it into something you can use first. Here’s a simple way using framework classes.
When given a generic data structure,
JavaScriptSerializerturns arrays intoArrayLists.