前段时间需要写DLL接程序传来的JSON字符串,且要取出键值对,字符串内内容还不一定。
最后采用循环遍历的方式实现:
var o = JObject.Parse(yourJsonString); foreach (JToken child in o.Children()) { //var property1 = child as JProperty; //MessageBox.Show(property1.Name + ":" + property1.Value); foreach (JToken grandChild in child) { foreach (JToken grandGrandChild in grandChild) { var property = grandGrandChild as JProperty; if (property != null) { MessageBox.Show(property.Name + ":" + property.Value); } } } }