c# - Parsing JSON key/value pairs with JSON.NET -
i have .net project. i'm using json.net library. need use library parse json. json looks this:
{"1":"name 1","2":"name 2"}
the object list of key/value pairs. trying figure out how use json.net 1) parse json , 2) loop through key/value pairs. there way this? if so, how?
the thing see de-serializing strongly-typed object.
thank much!
you can deserialize dictionary<string, string>
var dict = jsonconvert.deserializeobject<dictionary<string, string>>(json); foreach(var kv in dict) { console.writeline(kv.key + ":" + kv.value); }
since jobject implements idictionary
, can use jobject.parse
var dict = jobject.parse(@"{""1"":""name 1"",""2"":""name 2""}");
Comments
Post a Comment