C#json解析数组例子

String json="{"Data":[{"username":"410100h","activenum":"299784"},{"username":"69ejfb","activenum":"249741"}]}";

JObject jlist = (JObject)JsonConvert.DeserializeObject(a);
                //获取树形用户json字符串
                string userList = jlist["Data"].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["username"].ToString();
                    string type = j["activenum"].ToString();
                    Console.WriteLine("解析后数据:" + userid + " " + type);
                }
               注意.net需要4.5以上版本
使用到
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

你可能感兴趣的:(C#)