zoukankan      html  css  js  c++  java
  • json序列化

    1,引用

    插件:Newtonsoft.Json.dll

    命名空间:using Newtonsoft.Json;

    2,json序列化

            static void Serialize()
            {
                List<User> uList = new List<User>();
                uList.Add(new User { Name = "xihu", Age = 20, Sex = false });
                uList.Add(new User { Name = "qiyo", Age = 21, Sex = true });
                uList.Add(new User { Name = "mokg", Age = 22, Sex = false });
                //将user集合序列化
                string s = JsonConvert.SerializeObject(uList);
                Console.WriteLine(s);
            }

    3,反序列化

            //反序列化
    static void Deserialize(string jsonStr)
            {
                List<User> uList = JsonConvert.DeserializeObject<List<User>>(jsonStr);
                foreach(var u in uList)
                {
              Console.WriteLine($
    "姓名:{u.Name},年龄:{u.Age},性别:{u.Sex}"); } }

    不知道你们发现了没有,转换后性别的首字母变成了大写,原因吧,我暂时还不知道,睡觉去了,哈哈

  • 相关阅读:
    rpc rmi http
    理解Global interpreter lock
    maven scope含义的说明
    实现图片缩放
    实现在edittext中任意插入图片
    上传图片或文件到服务器端
    onResume
    关于Context
    android bitmap compress
    saveFile()方法
  • 原文地址:https://www.cnblogs.com/ecake/p/8542815.html
Copyright © 2011-2022 走看看