This is the JSON string that I am working with.
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);
I'm trying to get a list of values for SYMBOL, NAME, PRICE, & AGG_VOLUME. Here's my code so far:
var covg = feed["DataItem"]["@name"].Select(f => (string)f.SelectToken("#text"));
But I'm getting the following error:
Object reference not set to an instance of an object.
What am I doing wrong?