.net - Parsing json in C# without knowing indexes -
I want to parse this piece of JSON with JSON.NET in C #, but I do not know about it How to go in "" "": "967633758", "Classy": "" 302756826 "," Classy ":" 15 "," Instained "," 39, 3033 "," Instrated ":" 11040671 "," Zodiac ": "1", "Pause": 1}, "302756826": {"id": "302756826": "11041143", "zodiac": "1", "pos": 2}, ...}}
Full Jason:
I should get the element of every "RGIN" child, but I can not make a square for it because the item names are always changing.
I tried to use this code, but I always get an exception. / P>
dynamic jsObject = JsonConvert.DeserializeObject (jsonString); Console.light line ("position:" + jsObject ["success"]); // This works fine foreach (var i in jsObject ["rgInventory"]) {Console.WriteLine ("Item ID:" + i ["id"]); // This gives an exception} Exception:
Uncontrolled Exception: System. Nonprofit Operation Exception: Up to Child Value on Newtonsoft.Json.Linq.JProperty Can not reach.
This should work.
var jObj = (JObject) JsonConvert.DeserializeObject (JSON); Children in Forechha ("[" id "]]. ()". } Additionally, your code can be more readable by using the dynamic keyword: dynamic jObj = JsonConvert. DeserializeObject (json); Console.light line ("position:" + jObj.success); Foreclosure (Children in Joebiz.RGINDINRI). (Hair) ()) {console.light line ("Item ID: {0}", child.first.id); }
Comments
Post a Comment