基于WinCE的JSON 类库 源码
来源:互联网 发布:大数据世界 编辑:程序博客网 时间:2024/06/06 16:33
基于WinCE的JSON 类库,可以将对象序列化成字符串和文件。
提示,其在反序列化时有一个BUG:
如果对象的某个字段值为 null,将其序列化成字符串,然后将该字符串反序列化成对象时会报异常。
这个通常影响不大,在序列化时为对象的字段都提供一个非 null 的默认值即可。
测试代码:
internal class Program { private static void Main(string[] args) { string json = Converter.Serialize(new User("name", "password", AccountStatus.Enabled)); Converter.Serialize("out.txt", new int[] { 1, 2, 3, -4 }, "_"); Console.WriteLine(json); User user = Converter.Deserialize<User>(json, "_"); int[] values = Converter.DeserializeFromFile<int[]>("out.txt", "_"); Console.WriteLine(user.UserName); Console.WriteLine("Done. Press enter to exit"); Console.ReadLine(); } } public class BaseUser { private int _id = 1; } [SerializeIncludingBase] public class User : BaseUser { private string _userName; private string _password; [NonSerialized] private readonly Role _role; private AccountStatus _status; private Thing _think = new Thing(); public string UserName { get { return _userName; } set { _userName = value; } } public string Password { get { return _password; } set { _password = value; } } public AccountStatus Status { get { return _status; } set { _status = value; } } public Role Role { get { return _role; } } public Thing Thing { get { return new Thing(); } } public User(string userName, string password, AccountStatus status) { UserName = userName; Password = password; Status = status; _role = new Role(DateTime.Now, "Admin", this); } private User() { } } public class Role { public Role(DateTime expires, string name, User user) { Expires = expires; Name = name; User = user; } public DateTime Expires { get; set; } public string Name { get; set; } public User User { get; set; } public Thing Thing { get { return new Thing(); } } } public class Thing { private string _name = "ABC"; public string Name { get { return _name; } set { _name = value; } } } public enum AccountStatus { Enabled = 1, Disabled = 2, }
下载地址:
http://files.cnblogs.com/08shiyan/CodeBetter.JsonCF_v0.2_Source.zip
强大的 Newtonsoft.Json
http://files.cnblogs.com/08shiyan/Newtonsoft.Json.Compact.zip
之前一直用基于 .NET 的,没发现有基于 .NET CF 的,今天算是发现宝贝了。呵呵
文章转载自:
http://www.cnblogs.com/08shiyan/p/3198048.html
- 基于WinCE的JSON 类库 源码
- wince下的JSON
- 基于wince的录音机
- wince 能用的 Newtonsoft.Json(Json.Net)
- 基于wince的嵌入式开发
- 基于Wince的计算器程序
- 修改了wince下的JSON类。
- WinCE 能用的Json格式转换库
- wince驱动程序:基于WinCE的I2C驱动程序设计
- 基于ARM和WINCE的开发
- 基于WinCE的I2C驱动程序设计
- 基于WinCE的ARM视频监控系统
- 基于WinCE的ARM视频监控系统
- 基于WinCE的I2C驱动程序设计
- 基于WinCE模拟器的应用程序调试
- 基于WinCE模拟器的应用程序调试
- 基于WinCE模拟器的应用程序调试
- 基于WinCE模拟器的应用程序调试
- 枚举与Combox的SelectedIndex绑定出现怪异问题的解决方案
- 比特币持续性上涨或因美国两党谈判破裂
- 大大的世界
- Lua5.1代码阅读(四):lparser.h/lparser.c
- How to Revise her Restaurant?
- 基于WinCE的JSON 类库 源码
- Lua5.1代码阅读(五):lundump.h/lundump.c
- Linux 2.6内核配置说明(12----Instrumentation Support分析支持)
- 比特币——富者愈富效应初浮现
- Lua5.1代码阅读(六):ltm.h/ltm.c
- MongoDB 常用命令
- ubuntu 常用命令
- Lua5.1代码阅读(七):lvm.h/lvm.c
- [JavaScript学习]用面向对象方法实现拖拽效果