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); } } } }
为API生,为框架死,为debug奋斗一辈子;吃符号亏,上大小写的当,最后死在需求上。

浙公网安备 33010602011771号