Reputation: 1266
My simple json data as below
string _JsonData = @" {
"tm":{
"1":{
"pl":{
"11":{
"foo":"2"
},
"902":{
"foo":"70"
}
}
}
}";
I can get value of pl children's foo values (such as 2 and 70) as below code
JObject _JObject = JObject.Parse(_JsonData);
foreach (JToken _JTokenCurrent in _JObject["tm"]["1"]["pl"].Children())
{
MessageBox.Show(_JTokenCurrent["foo"].ToString());
}
So how can i get value of pl children's property values (such as 11 and 902)?
Thank you in advance.
Upvotes: 1
Views: 94
Reputation: 1266
OK I have solved as below;
JObject _JObject = JObject.Parse(_JsonData);
foreach (JToken _JTokenCurrent in _JObject["tm"]["1"]["pl"].Children())
{
// get values such as 11 and 902
JProperty _JTokenCurrentName = (JProperty)_JTokenCurrent;
MessageBox.Show(_JTokenCurrentName.Name);
/// get values such as 2 and 70
MessageBox.Show(_JTokenCurrent["foo"].ToString());
}
Upvotes: 1
Reputation: 6580
Not tested!
JObject _JObject = JObject.Parse(_JsonData);
foreach (JToken _JTokenCurrent in _JObject["tm"]["1"]["pl"].Children())
{
// Should be your 11 and 902
MessageBox.Show(_JTokenCurrent.Children().ToString());
// Should be your 2 nad 70
MessageBox.Show(_JTokenCurrent["foo"].ToString());
}
Upvotes: 0