C# .NET 遍历Json 形成键值对

前段时间需要写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);
                        }
                    }
                }
            }

 

posted @ 2019-08-09 08:47  ChaunceyWan  阅读(901)  评论(0编辑  收藏  举报