views:

2805

answers:

4

Hi! I have found different libraries that can parse Json data, but i did not find any documentation on how to get the data into an C# array or list.

I got this Json data:

{"001":{"Name":"John", "Phone":["Mob - 98837374","Mob - 98363627"]}, "002":{"Name":"Tom", "Phone":["Mob - 49858857"]}}

Anybody got a clue? :)

Edit:

Useful details posted by OP as comments re-posted as question edit by AnthonyWJones

My code using JSON.NET:

StringBuilder sb = new StringBuilder();
List<string> entities = (List<string>)JsonConvert.DeserializeObject(responseFromServer, typeof(List<string>));
foreach (string items in entities) {
  sb.Append(items);
}

But i always get an error when i debug:

Warning 1 Reference to type 'System.DateTimeOffset' claims it is defined in 'c:\Program >> Files\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE\mscorlib.dll', but it could not >> be found c:\Div\Json dot net\Bin\Newtonsoft.Json.dll"

+2  A: 

Have a look at this: http://stackoverflow.com/questions/401756/parsing-json-using-json-net

Lazarus
A: 

for what purpose you r going to use it... If you are using it on client side use the same json data because it would be huge in performance but if you need it in server side then search for an alternative method which converts json string to array list....

Pandiya Chendur
A: 

The JSON structure as it stands has some problems. It appears to be using property names such as "001" and "002" as data. This is fine in Javascript but its real tricky to handle in C#. A better stucture would be:-

[ {"ID": "001", "Name":"John", "Phone":["Mob - 98837374","Mob - 98363627"]},
  {"ID":"002", "Name":"Tom", "Phone":["Mob - 49858857"]} ]

Then JSON.NET as others have pointed to can be used more effectively.

AnthonyWJones
My code using JSON.NET:StringBuilder sb = new StringBuilder();List<string> entities = (List<string>)JsonConvert.DeserializeObject(responseFromServer, typeof(List<string>)); foreach (string items in entities) { sb.Append(items); }But i always get an error when i debug: "Warning 1 Reference to type 'System.DateTimeOffset' claims it is defined in 'c:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE\mscorlib.dll', but it could not be found c:\Div\Json dot net\Bin\Newtonsoft.Json.dll"
A: 

Since i am developing for a windows mobile device, it seems like Json.net is too large. I get an error when trying to debug, and i see that the whole device's memory is consumed.

Anyway... i think i'll just parse the Json string myself, as i know what the string will conclude.

Thank you for the suggestions anyway.

People on Stack overflow are great!

Better to comment on the answer rather than to use an answer spot as a discussion board.
jfar