I´ve got a JSON stored in a string named resultString it looks like this:
{"BRC1": {"image": "9b.jpg", "query": "led", "status": "ok", "data": {"value": {"LED_1": "OFF", "LED_2": "OFF", "LED_3": "OFF", "LED_4": "RED", "LED_5": "RED", "SILA": "ON", "ASLED": "ORANGE"}}}}
Now I want to get the value "BRC1" as string.
I tried this:
var data = (JObject)JsonConvert.DeserializeObject(resultString);
string resdevname = data["BRC1"].Value<string>();
also tried:
string resdevname = data[BRC1].Value<string>();
But I always get an Exception:
System.InvalidCastException: Cannot cast Newtonsoft.Json.Linq.JObject to Newtonsoft.Json.Linq.JToken.
what am I doing wrong?