tags:

views:

465

answers:

4

What is simpliest C# function to parse Json String into object and display it (C# xaml WPF)? (for example object wit 2 arrays - arrA and arrB)

+9  A: 

I think this is what you want:

JavaScriptSerializer JSS = new JavaScriptSerializer();
T obj = JSS.Deserialize<T>(String);
Rbacarin
+5  A: 
DataContractJsonSerializer serializer = 
    new DataContractJsonSerializer(typeof(YourObjectType));

YourObjectType = (YourObjectType)serializer.ReadObject(jsonStream);

You could also yuse the JavaScriptSerializer, but DataContractJsonSerializer is supposedly better able to handle complex types.

Oddly enough JavaScriptSerializer was once deprecated (in 3.5) and then resurrected because of ASP.NET MVC (in 3.5 SP1). That would definitely be enough to shake my confidence and lead me to use DataContractJsonSerializer since it is hard baked for WCF.

Justin Niessner
I'd use this over serializers built earlier in the framework's lifespan.
Will
+2  A: 

Just use the Json.NET library. It lets you parse Json format strings very easily:

JObject o = JObject.Parse(@"
{
    ""something"":""value"",
    ""jagged"":
    {
        ""someother"":""value2""
    }
}");

string something = (string)o.SelectToken("something");
Philip Daubmeier
+2  A: 

This answer might help you.

KMan