tags:

views:

867

answers:

4

what is the best way to deserialize array of json objects without asp.net?

Json format: {"results" : [ { "a": "value A", "b": "value B"}, { "c": "value C", "d": "value D"}]}

Please note: Json object should be deserialized into .Net object.

A: 

With JavaScript you'd do:

var myObj = eval('(' + jsonString + ')');
Kon
I am looking for deserializing Json object into .net objects. and not json string into json object.
Software Enthusiastic
+1  A: 

A lot of implementations in different languages are provided at http://www.json.org/ (the bottom of the page)

EDIT: apparently that page doesn't mention the built in JSON support while it does exist in .Net 3.5 according to MSDN

Jauco
I dont want to use any third party library... It would be better if I can directly use .Net framework class library for this purpose...
Software Enthusiastic
The System.Runtime.Serialization.Json IS part of the .NET BCL. The DataContractJsonSerializer class does exactly what you're asking for. Don't confuse WCF with ASP.NET; they are definitely not the same. WCF does not require ASP.NET at all in order to do what it does.
Alan McBee
A: 

In PHP, for instance, you can do:

$json = json_decode($json_string);

and that will convert your JSON into an object/array

KyleFarris
I am looking for deserializing Json object into .net objects. and not json string into json object.
Software Enthusiastic
+2  A: 

The Json.NET library, available here:

http://james.newtonking.com/projects/json-net.aspx

Works great.

richardtallent