Here is my sample JSON data representation:
{ "parts" : {
"part" : [
{ "name" : "Mainboard" },
{ "name" : "Keyboard" },
{ "name" : "CPU" },
{ "name"" : "FAN" }
] }
}
Nothing complicated to this point. Now, I want to read the array of objects declared inside the part element. To do this, I am going to declare an instance of JsonObject and JsonArray. While JsonObject handles single objects, an array will contain a multitude of objects.
An important note to be made is that you need to reference the System.Json library in order to work with the above mentioned classes.
Initially, I stored the existing JSON code in a sample string:
string jsonString = @"{ ""parts"" : {
""part"" : [
{ ""name"" : ""Mainboard"" },
{ ""name"" : ""Keyboard"" },
{ ""name"" : ""CPU"" },
{ ""name"" : ""FAN"" }
] }
}";
Read more: DZone