I try to parse string inside 2nd curly brackets using C# / json
String looks like this:
{"R27":{"DEVX":0.1346224}}
My aim is read value of DEVX, which is 0.1346224
I've tried:
var joR = JObject.Parse(R);
string R27 = joR["R27"].ToString();
RETURNS : {"DEVX":0.1346224}}
string R27 = joR["DEVX"].ToString();
RETURNS ERROR
Is there way to get directly value "0.1346224" without playing with string?
Yes, absolutely - assuming you know the two names involved, you can just index twice, once to get the object for R27
, then once within that object to get the value of DEVX
:
using System;
using Newtonsoft.Json.Linq;
public class Test
{
static void Main()
{
string json = "{\"R27\":{\"DEVX\":0.1346224}}";
var obj = JObject.Parse(json);
double devX = (double) obj["R27"]["DEVX"];
Console.WriteLine(devX);
}
}
See more on this question at Stackoverflow