This is a mirror of official site: http://jasper-net.blogspot.com/

Working with JSON in .NET – a Silverlight example

| Thursday, June 3, 2010
Unlike any other .NET sub-framework, Silverlight has built capabilities to work with JSON. In this article, I am focusing on JsonObject, a class that can help the developer work with JSON content.

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

Posted via email from jasper22's posterous

0 comments: