• 获取json字段的key和value


    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;
                               
                             
                            }
                           
                        }
                    }
                }
  • 相关阅读:
    算法演示工具
    1198:逆波兰表达式
    1315:【例4.5】集合的划分
    1192:放苹果
    1191:流感传染
    1354括弧匹配检验
    1331【例1-2】后缀表达式的值
    1307高精度乘法
    1162字符串逆序
    1161转进制
  • 原文地址:https://www.cnblogs.com/my2020/p/12492812.html
Copyright © 2020-2023  润新知