zoukankan      html  css  js  c++  java
  • C# 解析json数组

    案例一:

    string json = "[{"Groupid":"54","groupnum":"66000","groupname":"大唐移动","type":"0","dnsprefix":"","islocal":"1","canshowall":"-1","user":[{"userid":"66001","username":"66001","type":"6","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"0","cstate":"0"},{"userid":"66002","username":"66002","type":"6","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"0","cstate":"0"},{"userid":"66003","username":"66003","type":"6","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"0","cstate":"0"},{"userid":"66004","username":"66004","type":"6","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"0","cstate":"0"},{"userid":"66005","username":"66005","type":"0","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"1","cstate":"0"},{"userid":"66006","username":"66006","type":"0","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"0","cstate":"0"},{"userid":"66007","username":"66007","type":"0","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"0","cstate":"0"},{"userid":"66008","username":"66008","type":"0","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"0","cstate":"0"}],"group":[]}]";

            //解析用户组json

            private void UpdateGroup_mem_Controls(string json)

            {

                JArray userArry = (JArray)JsonConvert.DeserializeObject(json);

                //获取树形用户json字符串

                string userList = userArry[0]["user"].ToString();

                //解析用户json信息

                JArray jar = (JArray)JsonConvert.DeserializeObject(userList);

                for (int i = 0; i < jar.Count; i++)

                {

                    JObject j = JObject.Parse(jar[i].ToString());

                    string userid = j["userid"].ToString();

                    string type = j["type"].ToString();

                    string username = j["username"].ToString();

                }

            }

    ----------------------------------------------------------------

    案例二:

    string json = [{"userid":"66001","username":"66001","type":"6","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"0","cstate":"0"},{"userid":"66002","username":"66002","type":"6","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"0","cstate":"0"},{"userid":"66003","username":"66003","type":"6","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"0","cstate":"0"},{"userid":"66004","username":"66004","type":"6","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"0","cstate":"0"},{"userid":"66005","username":"66005","type":"0","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"1","cstate":"0"},{"userid":"66006","username":"66006","type":"0","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"0","cstate":"0"},{"userid":"66007","username":"66007","type":"0","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"0","cstate":"0"},{"userid":"66008","username":"66008","type":"0","dnsprefix":"","othernumber":"","othername":"","islocal":"1","rstate":"0","cstate":"0"}]

                    JArray userArry = (JArray)JsonConvert.DeserializeObject(json);

                    Dictionary<string, string> dic = new Dictionary<string, string>();

                    //获取树形用户json字符串

                    foreach (var item in userArry)

                    {

                        JObject j = JObject.Parse(item.ToString());

                        dic.Add(j["userid"].ToString(), j["username"].ToString());

                    }

      

  • 相关阅读:
    9011,9012,9013,9014,8050,8550三极管的区别
    XP制动关机CMD命令
    搭建系统框架发现的三个Web.Config问题
    监听公众号返回按钮,直接退出到公众号页面
    微信公众号h5页面自定义分享
    博客园页面设置
    js 中加减乘除 比较精确的算法,js本身有些运算会出错,这里给出较精确的算法
    HTML属性
    HTML属性
    处理ajax数据;数据渲染(细节)
  • 原文地址:https://www.cnblogs.com/yuyexiaoxiao/p/13537101.html
Copyright © 2011-2022 走看看