.net 解析json格式数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq736150416/article/details/78835688
            string funcInfo = "";
            string json = "[{\"funcscope_category\":{\"id\":1}},{\"funcscope_category\":{\"id\":15}}]";

            JArray jarryFuncInfo = (JArray)JsonConvert.DeserializeObject(json);
            if (jarryFuncInfo != null && jarryFuncInfo.Count > 0)
            {
                for (int i = 0; i < jarryFuncInfo.Count; i++)
                {
                    JObject objFunc = (JObject)jarryFuncInfo[i];

                    funcInfo += objFunc["funcscope_category"]["id"] + ",";
                }
            }

            Response.Write(funcInfo);




             int id = 0;
            string json02 = "{\"id\": 2 }";
            JObject jarry02 = (JObject)JsonConvert.DeserializeObject(json02);
            if (jarry02 != null && jarry02.Count > 0)
            {
                id = Convert.ToInt32(jarry02["id"]);
            }
            Response.Write(id);

展开阅读全文

没有更多推荐了,返回首页