I want to count all data using C# from this JSON
[
{
"p_id": "0001",
"p_name": "Tester"
},
{
"p_id": "197921",
"p_name": "Kanza"
}
]
How to determine that in this JSON there are 2 objects?
I want to count all data using C# from this JSON
[
{
"p_id": "0001",
"p_name": "Tester"
},
{
"p_id": "197921",
"p_name": "Kanza"
}
]
How to determine that in this JSON there are 2 objects?
If you use Newtonsoft.JSON you can do something like the below.
var jsonstring = "[{'p_id': '0001','p_name': 'Tester'},{'p_id': '197921','p_name': 'Kanza'}]";
var json = JsonConvert.DeserializeObject<JArray>(jsonstring);
int length = json.Count;
length will give you the number of items in your JSON array. Proof is below
You can get the length like this:
var jsonstring = "[{'p_id': '0001','p_name': 'Tester'},{'p_id': '197921','p_name': 'Kanza'}]";
int length = ((JArray)jsonstring).Count;