xtechkid xtechkid - 3 months ago 26
JSON Question

Reading JSON Object Value in C# code

Folks,
I am trying to access a json value from Azure ML rest service but i get a null value all the time, i tried different options but it did not work. Can u please provide ideas.

Json String

{
"Results": {
"output1": {
"type": "table",
"value": {
"ColumnNames": ["Sentiment",
"Score"],
"ColumnTypes": ["String",
"Double"],
"Values": [["negative",
"0.20"],
**["negative",
"0.03"]**]
}
}
}
}


Trying to fetch the value between **

Tried the below.

using Newtonsoft.Json.Linq;
JObject o = JObject.Parse(sentimentvalue);
string valv = (string)o.SelectToken("Results[0].output1[0].Values[0]");

Answer

Your JSON path in the SelectToken seems to be wrong. Try this:

string valv = (string)o.SelectToken("$.Results.output1.value.Values[0][1]");