Stewie Griffin
Stewie Griffin

Reputation: 9327

Deserialize json in C#

I am trying to deserialize this json using C#:

{"query":
    {"count":10,"created":"2011-06-18T19:15:24Z","lang":"en-US","results":
          {"Result":[{"id":"21373494","Title":"Sushi Bistro","Address":"455 Balboa     St","Rating":
              {"AverageRating":"5"}   
          } 
          {"Result":[{"id":"21373495","Title":"Sushi Bistro","Address":"4565 Balboa     St","Rating":
              {"AverageRating":"1"}   
          } 
    }
 }

I tried Newton json.NET, then used JSONHelper class, but it didn't work. Could someone provide a short sample how to deserialize to the object and loop through 'Result' in C#?

UPDATE: sorry for invalid json, ouput is crazy big, so I tried to copy just a small part. However you can see a pattern of Result set in here.

Upvotes: 0

Views: 1198

Answers (1)

Andrew Orsich
Andrew Orsich

Reputation: 53695

Json provided above is invalid, try to fix json first and after this i guess your code will work.

You can use jsonlint service to validate json.

Example of deserializing json from string using newton json dll:

var json = "..";

string output = JsonConvert.DeserializeObject<MyClass>(json);

Upvotes: 3

Related Questions