1、获取对应key的值
JObject jt = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>("{"test1":"aaaa","test2":"bbbbbb"}"); Console.Write(jt["test1"].ToString()); Console.Write(jt["test2"].ToString());
2、获取key和value
string json = "{"a":"a","s":"s","d":"f","f":f}"; var o = JObject.Parse(json); foreach (var item in o.Children()) { var p = item as JProperty; string s = p.Name + ":" + p.Value; }
string json = "{"a":[{"a":"a","s":"s","d":"d","f":f},{"a":"a","s":"s","d":"d","f":f},{"a":"a","s":"s","d":"d","f":f}]}"; var o = JObject.Parse(json); Console.WriteLine(o); Console.Read(); foreach (JToken child in o.Children()) { foreach (JToken grandChild in child) { foreach (JToken grandGrandChild in grandChild) { foreach (var item in grandGrandChild.Children()) { var p = item as JProperty; string s = p.Name + ":" + p.Value; } } } }