Unable to parse json with complex object using JOject.Parse

Priya
Priya
Member
62 Points
26 Posts

Hi,

I a using package Newtonsoft.Json.Linq to parse json string

string jsonstr="[{\"home\":{\"inning\":[{\"@number\":\"1\",\"@score\":\"0\"},{\"@number\":\"2\",\"@score\":\"1\"},{\"@number\":\"3\",\"@score\":\"0\"},{\"@number\":\"4\",\"@score\":\"0\"},{\"@number\":\"5\",\"@score\":\"0\"},{\"@number\":\"6\",\"@score\":\"0\"},{\"@number\":\"7\",\"@score\":\"0\"},{\"@number\":\"8\",\"@score\":\"0\"},{\"@number\":\"9\",\"@score\":\"0\"}]}}]"
JObject jOject=JObject.Parse(jsonstr);

But it show invalid json format. What is wrong?

Thanks in advance.

Views: 8182
Total Answered: 1
Total Marked As Answer: 1
Posted On: 10-Mar-2016 07:48

Share:   fb twitter linkedin
Answers
NiceOne Team
NiceOne...
Admin
404 Points
67 Posts
         

Hi Priya,

Since JOject parse a single json string and in your json string look like an array.

So you need to use JArray.Parse(jsonstr) 

JArray jarray JArray.Parse(jsonstr);
Posted On: 10-Mar-2016 07:56
 Log In to Chat