c# - Parsing JSON Array in .NET 2.0 -
I am using JSON.NET to parse my server via some JSON. I feel as dumb, because I think I'm trying to do something easy. However, the code does not work At present, I'm getting some Jason Bon from the server which looks like this:
[{id: '1', Description: 'Some kind Description '}, {id:' 2 ', Details:' Another description '}, {ID:' 3 ', Description:' This is another '}]
Currently , I'm trying to take this JSON into C #; it's a dictionary & lt; String, string & gt;
. My (unsuccessful) attempt looks like this:
Private dictionary There is such a code which seems so simple I think I have to do something wrong In fact, this is not working, so something must be wrong. I can not determine right now
Thanks for any help you can provide. Please remember, this is based on the .NET 2.0 framework.
You do not need to parse manually JSON string strongly by using JSON.NET Can compile it in a typed archive
class MyClass {public string id {get; Set; } Public string description {get; Set; }}
Then
string json = @ "[{id: '1', description:" Description of some sort '}, {id: '2', Description: 'Other Details'}, {id: '3', Description: 'Here's another'}] "; & Lt; MyClass & gt; Collection = JsonConvert.DeserializeObject & lt; List & lt; MyClass & gt; & Gt; (JSN); Vorach (various items in the collection) console WrightLine (item.id + "-" + item.description);
or you can change it in any dictionary
Glossary & lt; String, string & gt; Dict = collection.ToDictionary (E => E.D., E => E. Description);
Comments
Post a Comment