MattyAB MattyAB - 5 months ago 13
JSON Question

C# JSON Parse gives error 'System.ArgumentNullException' when parsing JSON array

I'm trying to parse this JSON:

{"error":[],"result":{"XETHXXBT":{"a":["0.023769","64","64.000"],"b":["0.023756","42","42.000"],"c":["0.023756","1.21518360"],"v":["74038.22109284","130984.00945101"],"p":["0.023689","0.006974"],"t":[1272,2332],"l":["0.023440","0.023440"],"h":["0.024091","0.024669"],"o":"0.024084"}}}


The piece of data I want to get is

"c":["0.023756","1.21518360"],


More to the point, the first value of "c". The code I am using is:

JObject jObject = JObject.Parse(json);
double balance = (double)jObject["c"];


What am I doing wrong? How can I just get the first value of the "c" array?

Thanks!

Here is the full error report: http://pastebin.com/4S204aUG

Answer

To get to c do the following:

var o = JObject.Parse(<yourjsontext>);
var result = o["result"];
var XETHXXBT = result["XETHXXBT"];
var c = XETHXXBT["c"];

var value1 = (double) c[0];
var value2 = (double) c[1];