My json data are as below.
{
"data":{
"foo":{
"sfoo":"1",
"active":1
},
"foo":{
"sfoo":"2",
"active":0
},
"v":"v1"
}
}
I try to get the value from json with this code:
JObject _JObject = JObject.Parse(_JsonString);
var _JItems = _JObject.SelectToken("data[0].foo")
.Select(s => new
{
_Sfoo = (string)s.SelectToken("sfoo"),
_WhereClause = (string)s.SelectToken("active")
})
.Where(w => w._WhereClause == "1");
foreach (var _JItem in _JItems)
{
MessageBox.Show(_JItem._Sfoo.ToString());
}
I am getting an error such as "Additional information: Value cannot be null."
Thank you in advance.
datais not an array, and the firstfooproperty of the objectdatawill be overwritten by the secondfooproperty. Maybe you meant to makedataan array?