zoukankan      html  css  js  c++  java
  • litjson的用法

    LitJSON是一个.NET平台下处理JSON格式数据的类库,小巧、快速。它的源代码使用C#编写,可以通过任何.Net平台上的语言进行调用,可以直接把实体类转换成Json对象,也可以把Json对象转换成实体类。

    protected void Page_Load(object sender, EventArgs e)
            {
                Json2Object();
                Object2Json();
            }
            /// <summary>
            /// 读取json数据
            /// </summary>
            void Json2Object()
            {
                string str = "{'name':'liming','age':'18','temps':[{'temp':'t1'},{'temp':'t2'}]}";
    
                //读取json数据,
                JsonData jd = JsonMapper.ToObject(str);
                string name = (string)jd["name"];
                int age = (int)jd["age"];
                //多个数组,foreach读取单个数据
                JsonData temps = jd["temps"];
                foreach (JsonData item in temps)
                {
                    string temp = (string)item["temp"];
                }
            }
            /// <summary>
            /// 实体类转换成Json
            /// </summary>
            void Object2Json()
            {
                Team team = new Team();
    
                team.name = "liming";
                team.age = 18;
                team.temps=new List<Team.Temps>();
                for(int i=1;i<3;i++)
                {
                    var temp = new Team.Temps();
                    temp.temp = i.ToString();
                    team.temps.Add(temp);
                }
                string json = JsonMapper.ToJson(team);
    
            }
            /// <summary>
            /// 实体类
            /// </summary>
            public class Team
            {
                public string name { get; set; }
                public int age { get; set; }
                public List<Temps> temps { get; set; }
                public class Temps
                {
                    public string temp { get; set; }
                }
            }

    Listjson下载地址:http://www.edowning.net/soft/81656.htm

  • 相关阅读:
    基本数据类型(int, bool, str)
    万恶之源之运算符
    python基础初识
    leetcode 653. Two Sum IV
    leetcode 16 3Sum Closest
    leetcode15 3Sum
    leetcode 1 Two Sum
    【站立会议】第四天
    【站立会议】第三天
    【站立会议】第二天
  • 原文地址:https://www.cnblogs.com/housh/p/4421512.html
Copyright © 2011-2022 走看看