• 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 + "
    " + uid + "
    " + result + "
    " + user + "
    " + group + "
    " + gate + "
    " + 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;          
            }
  • 相关阅读:
    201521123084 《Java程序设计》第4周学习总结
    201521123084 《Java程序设计》第3周学习总结
    C语言博客作业—数据类型
    c语言博客作业-函数
    java课程设计——猜数游戏个人博客
    java课程设计-猜数游戏
    201521123092《java程序设计》第14周学习总结
    201521123092《java程序设计》第十三周学习总结
    201521123092《java程序设计》第12周学习总结
    201521123092《java程序设计》第十一周学习总结
  • 原文地址:https://www.cnblogs.com/xiaoyao095/p/3552398.html
Copyright © 2020-2023  润新知