WPF Json字符串解析(同样适合WinFrom、WebFrom)

Newtonsoft.Json序列化和反序列化。
下载地址:http://www.newtonsoft.com/products/json/

Json解析:

方法一:  

        /// <summary>

        /// Json解析

        /// </summary>

        /// <param name="JsonText">传入的Json字符串</param>

        /// <returns>返回集合List</returns>

        public List<string> JsonResult(string JsonText)

        {

            List<string> list = new List<string>();

            var json2 = (JObject)JsonConvert.DeserializeObject(JsonText);

            var vid = json2["vid"];

            var uid = json2["uid"];

            var Object = json2["object"];

            var json3 = (JObject)JsonConvert.DeserializeObject(Object.ToString());

            var result = json3["result"];

            var user = json3["user"];

            var group = json3["group"];

            var gate = json3["gate"];

            var datetime = json3["datetime"];

            list.Add(vid.ToString());

            list.Add(uid.ToString());

            list.Add(Object.ToString());

            list.Add(result.ToString());

            list.Add(user.ToString());

            list.Add(group.ToString());

            list.Add(gate.ToString());

            list.Add(datetime.ToString());

            return list;

        }

方法二:

        /// <summary>

        /// Json解析

        /// </summary>

        /// <param name="JsonText">传入的Json字符串</param>

        /// <returns>返回字符串</returns>

        public String JsonResult(string JsonText)

        {

            var json2 = (JObject)JsonConvert.DeserializeObject(JsonText);

            var vid = json2["vid"];

            var uid = json2["uid"];

            var Object = json2["object"];

            var json3 = (JObject)JsonConvert.DeserializeObject(Object.ToString());

            var result = json3["result"];

            var user = json3["user"];

            var group = json3["group"];

            var gate = json3["gate"];

            var datetime = json3["datetime"];

            string strText = vid + "\n" + uid + "\n" + result + "\n" + user + "\n" + group + "\n" + gate + "\n" + datetime;

            return strText;

        }

方法三:

        /// <summary>

        /// 解析Json

        /// </summary>

        /// <param name="JsonText">传入的Json字符串</param>

        /// <returns>返回数组</returns>

        public String[] JsonResult(string JsonText)

        {

            string[] str = new string[7];

            var json2 = (JObject)JsonConvert.DeserializeObject(JsonText);

            var vid = json2["vid"];

            var uid = json2["uid"];

            var Object = json2["object"];

            var json3 = (JObject)JsonConvert.DeserializeObject(Object.ToString());

            var result = json3["result"];

            var user = json3["user"];

            var group = json3["group"];

            var gate = json3["gate"];

            var datetime = json3["datetime"];

            str[0] = vid.ToString();

            str[1] = uid.ToString();

            str[2] = result.ToString();

            str[3] = user.ToString();

            str[4] = group.ToString();

            str[5] = gate.ToString();

            str[6] = datetime.ToString();

            return str;          

        }

 

你可能感兴趣的:(json)