zoukankan      html  css  js  c++  java
  • 读取Json

            private void DeserializeJson()
            {
                string content = "";
                string input = "{'key1':{'Name':'ZhangSan','Age':20},'key2':{'Name':'LiSi','Age':21},'key3':{'Name':'WangWu','Age':22}}";
                try
                {
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    Dictionary<string, object> jsonList = serializer.DeserializeObject(input) as Dictionary<string, object>;
                    foreach (KeyValuePair<string, object> obj in jsonList)
                    {
                        string valText = "";
                        Dictionary<string, object> property = obj.Value as Dictionary<string, object>;
                        foreach (KeyValuePair<string, object> pro in property)
                        {
                            valText += string.Format("{0}{1}:{2}", string.IsNullOrEmpty(valText) ? "" : ",", pro.Key, pro.Value);
                        }
                        content += string.Format("{0}:[{1}]\n", obj.Key, valText);
                    }

                }
                catch (ArgumentException)
                {
                    throw new ArgumentException("输入Json字符串有误,请重新输入!");
                }
                catch (NullReferenceException)
                {
                    throw new NullReferenceException("未能找到可用对象!");
                }
            }
  • 相关阅读:
    Python服务器开发三:Socket
    系统性能检测工具之lsof
    系统性能检测工具之iostat
    系统性能检测工具之vmstat
    系统性能检测工具之sar
    系统性能检测工具之ps
    系统性能检测工具之top
    Linux常用命令大全
    授权
    RMAN之REPORT命令
  • 原文地址:https://www.cnblogs.com/zhangqs008/p/2802212.html
Copyright © 2011-2022 走看看