Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Since jsonData["nodes"] here is a JObject, then jsonData["nodes"].Children() is an enumerable containing the JProperties. Each JProperty has a Name and a Value. You just need to cast the JToken back to JProperty (or JObject) as appropriate.

Change your foreach loop to this:

foreach (JProperty node in nodes) { string nodeName = node.Name; JObject speaker = (JObject)node.Value; float attenuation = (float)speaker["att"]; int channel = (int)speaker["ch"]; } 

By the way, if you have a JToken and you don't know what type it is, (e.g. JProperty, JObject, JArray, etc.) you can look at the Type property on the JToken.

If your ultimate goal is merely to convert the JSON to regular dictionaries and lists, you might find this answerthis answer helpful.

Since jsonData["nodes"] here is a JObject, then jsonData["nodes"].Children() is an enumerable containing the JProperties. Each JProperty has a Name and a Value. You just need to cast the JToken back to JProperty (or JObject) as appropriate.

Change your foreach loop to this:

foreach (JProperty node in nodes) { string nodeName = node.Name; JObject speaker = (JObject)node.Value; float attenuation = (float)speaker["att"]; int channel = (int)speaker["ch"]; } 

By the way, if you have a JToken and you don't know what type it is, (e.g. JProperty, JObject, JArray, etc.) you can look at the Type property on the JToken.

If your ultimate goal is merely to convert the JSON to regular dictionaries and lists, you might find this answer helpful.

Since jsonData["nodes"] here is a JObject, then jsonData["nodes"].Children() is an enumerable containing the JProperties. Each JProperty has a Name and a Value. You just need to cast the JToken back to JProperty (or JObject) as appropriate.

Change your foreach loop to this:

foreach (JProperty node in nodes) { string nodeName = node.Name; JObject speaker = (JObject)node.Value; float attenuation = (float)speaker["att"]; int channel = (int)speaker["ch"]; } 

By the way, if you have a JToken and you don't know what type it is, (e.g. JProperty, JObject, JArray, etc.) you can look at the Type property on the JToken.

If your ultimate goal is merely to convert the JSON to regular dictionaries and lists, you might find this answer helpful.

added some more helpful info
Source Link
Brian Rogers
  • 130.4k
  • 31
  • 315
  • 315

Since jsonData["nodes"] here is a JObject, then jsonData["nodes"].Children() is an enumerable containing the JProperties. Each JProperty has a Name and a Value. You just need to cast the JToken back to JProperty (or JObject) as appropriate.

Change your foreach loop to this:

foreach (JProperty node in nodes) { string nodeName = node.Name; JObject speaker = (JObject)node.Value; float attenuation = (float)speaker["att"]; int channel = (int)speaker["ch"]; } 

By the way, if you have a JToken and you don't know what type it is, (e.g. JProperty, JObject, JArray, etc.) you can look at the Type property on the JToken.

If your ultimate goal is merely to convert the JSON to regular dictionaries and lists, you might find this answer helpful.

Since jsonData["nodes"] here is a JObject, then jsonData["nodes"].Children() is an enumerable containing the JProperties. Each JProperty has a Name and a Value. You just need to cast the JToken back to JProperty (or JObject) as appropriate.

Change your foreach loop to this:

foreach (JProperty node in nodes) { string nodeName = node.Name; JObject speaker = (JObject)node.Value; float attenuation = (float)speaker["att"]; int channel = (int)speaker["ch"]; } 

Since jsonData["nodes"] here is a JObject, then jsonData["nodes"].Children() is an enumerable containing the JProperties. Each JProperty has a Name and a Value. You just need to cast the JToken back to JProperty (or JObject) as appropriate.

Change your foreach loop to this:

foreach (JProperty node in nodes) { string nodeName = node.Name; JObject speaker = (JObject)node.Value; float attenuation = (float)speaker["att"]; int channel = (int)speaker["ch"]; } 

By the way, if you have a JToken and you don't know what type it is, (e.g. JProperty, JObject, JArray, etc.) you can look at the Type property on the JToken.

If your ultimate goal is merely to convert the JSON to regular dictionaries and lists, you might find this answer helpful.

Source Link
Brian Rogers
  • 130.4k
  • 31
  • 315
  • 315

Since jsonData["nodes"] here is a JObject, then jsonData["nodes"].Children() is an enumerable containing the JProperties. Each JProperty has a Name and a Value. You just need to cast the JToken back to JProperty (or JObject) as appropriate.

Change your foreach loop to this:

foreach (JProperty node in nodes) { string nodeName = node.Name; JObject speaker = (JObject)node.Value; float attenuation = (float)speaker["att"]; int channel = (int)speaker["ch"]; }