我的简单json数据如下
string _JsonData = @" {
"tm":{
"1":{
"pl":{
"11":{
"foo":"2"
},
"902":{
"foo":"70"
}
}
}
}";
我可以得到pl子节点的foo值(如2和70)的值,如下代码
JObject _JObject = JObject.Parse(_JsonData);
foreach (JToken _JTokenCurrent in _JObject["tm"]["1"]["pl"].Children())
{
MessageBox.Show(_JTokenCurrent["foo"].ToString());
}
那么我怎么能得到pl子属性值的值(如11和902)?
提前感谢。
OK我已经解决如下;
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());
}
未测试!
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());
}