前段時間需要寫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); } } } }