C#json 해석 배열 예

5091 단어 C#
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;

좋은 웹페이지 즐겨찾기