这是我正在使用的 JSON 字符串。
string jsonText = "{
"?xml" : {
"@version" : "1.0",
"@encoding" : "UTF-8",
"@standalone" : "yes"
},
"Grid" : {
"DataRow" : [{
"DataItem" : [{
"@name" : "SYMBOL",
"#text" : "005930"
}, {
"@name" : "NAME",
"#text" : "Samsung Electronics"
}, {
"@name" : "PRICE",
"#text" : "1004.3"
}, {
"@name" : "VOLUME",
"#text" : "273.182"
}, {
"@name" : "AGG_VOLUME",
"#text" : "302.894"
}
]
}, {
"DataItem" : [{
"@name" : "SYMBOL",
"#text" : "AAPL"
}, {
"@name" : "NAME",
"#text" : "Apple Inc."
}, {
"@name" : "PRICE",
"#text" : "99"
}, {
"@name" : "VOLUME",
"#text" : "32936.4"
}, {
"@name" : "AGG_VOLUME",
"#text" : "33078.769"
}
]
}, {
"DataItem" : [{
"@name" : "SYMBOL",
"#text" : "MSFT"
}, {
"@name" : "NAME",
"#text" : "Microsoft Corporation"
}, {
"@name" : "PRICE",
"#text" : "42"
}, {
"@name" : "VOLUME",
"#text" : "103441.6"
}, {
"@name" : "AGG_VOLUME",
"#text" : "1324432.074"
}
]
}
]
}
}"
JObject feed = JObject.Parse(jsonText);
我正在尝试获取 SYMBOL、NAME、PRICE 和 AGG_VOLUME 的值列表。到目前为止,这是我的代码:
var covg = feed["DataItem"]["@name"].Select(f => (string)f.SelectToken("#text"));
但我收到以下错误:
你调用的对象是空的。
我究竟做错了什么?