Frank Krueger
Frank Krueger

Reputation: 70993

JSON Parsing in Silverlight 3.0

I have a bunch of little JSON object fragments of the form:

{ id: "wow", foo: 45.4, bar: "hello, world!" }

By "a bunch" I mean about 6 GB worth. :-) (And yes, I know, this isn't technically JSON. The full story is that it originally came from YAML data, but I find that most "JSON" parsers can handle this subset of YAML just fine.)

Currently, I use Netonsoft's JSON parser with the line:

var obj = Newtonsoft.Json.Linq.JObject.Parse(json);

This works well for me, but I am porting my WinForms app to Silverlight 3.0 (and onward to 4.0 once I get the chance).

From Googling around, I see that there is some "DataContractSuperJavaScriptExSerializer2" library from Microsoft that does JSON parsing.

Should I use that library, or is there something better on the horizon? I'm 30 mins away from writing my JSON parser so that I can ensure that it is efficient, but I thought I would see if there is anything else worth looking at in the Silverlight 3 world.

Upvotes: 0

Views: 941

Answers (1)

Michael S. Scherotter
Michael S. Scherotter

Reputation: 10785

Add a referece to System.Json and System.Runtime.Serialization.Json

#using System.Json;

using (var reader = new StringReader(jsonText))
{
    var response = JsonValue.Load(reader) as JsonObject;

    /// parse your code here
}

Upvotes: 3

Related Questions