zhangqs008
        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("未能找到可用对象!");
            }
        }

分类:

技术点:

相关文章:

  • 2022-01-01
  • 2021-06-29
  • 2022-12-23
  • 2021-08-22
  • 2022-01-01
  • 2022-01-01
  • 2022-01-01
  • 2022-01-01
猜你喜欢
  • 2021-10-28
  • 2021-10-06
  • 2022-01-23
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
相关资源
相似解决方案