Windows Phone开发经验谈(5)-Json的序列化和反序列化
wp7默认是支持序列化的..但是在这里给大家推荐一个类库Newtonsoft.Json,现在叫Json.net 下载地址:http://json.codeplex.com/releases/view/87440
序列化的例子:
Product product = new Product(); product.Name = "Apple"; product.Expiry = new DateTime(2008, 12, 28); product.Price = 3.99M; product.Sizes = new string[] { "Small", "Medium", "Large" }; string json = JsonConvert.SerializeObject(product);//{// "Name": "Apple",// "Expiry": new Date(1230422400000),// "Price": 3.99,// "Sizes": [// "Small",// "Medium",// "Large"// ]//} Product deserializedProduct = JsonConvert.DeserializeObject<Product>(json);
Linq to json的例子
string json = @"{ ""Name"": ""Apple"", ""Expiry"": new Date(1230422400000), ""Price"": 3.99, ""Sizes"": [ ""Small"", ""Medium"", ""Large"" ]}"; JObject o = JObject.Parse(json); string name = (string)o["Name"];// Apple JArray sizes = (JArray)o["Sizes"]; string smallest = (string)sizes[0];// Small
Json.NET | DataContractJsonSerializer | JavaScriptSerializer | |
Supports JSON | ![]() |
![]() |
![]() |
Supports BSON | ![]() |
![]() |
![]() |
Supports JSON Schema | ![]() |
![]() |
![]() |
Supports .NET 2.0 | ![]() |
![]() |
![]() |
Supports .NET 3.5 | ![]() |
![]() |
![]() |
Supports .NET 4.0 | ![]() |
![]() |
![]() |
Supports Silverlight | ![]() |
![]() |
![]() |
Supports Windows Phone | ![]() |
![]() |
![]() |
Open Source | ![]() |
![]() |
![]() |
MIT License | ![]() |
![]() |
![]() |
LINQ to JSON | ![]() |
![]() |
![]() |
Thread Safe | ![]() |
![]() |
![]() |
XPath-like JSON query syntax | ![]() |
![]() |
![]() |
Indented JSON support | ![]() |
![]() |
![]() |
Efficient dictionary serialization | ![]() |
![]() |
![]() |
Nonsensical dictionary serialization | ![]() |
![]() |
![]() |
Deserializes IList, IEnumerable, ICollection, IDictionary properties | ![]() |
![]() |
![]() |
Serializes circular references | ![]() |
![]() |
![]() |
Supports serializing objects by reference | ![]() |
![]() |
![]() |
Deserializes polymorphic properties and collections | ![]() |
![]() |
![]() |
Supports including type names with JSON | ![]() |
![]() |
![]() |
Globally customize serialization process | ![]() |
![]() |
![]() |
Supports excluding null values when serializing | ![]() |
![]() |
![]() |
Supports SerializationBinder | ![]() |
![]() |
![]() |
Conditional property serialization | ![]() |
![]() |
![]() |
Includes line number information in errors | ![]() |
![]() |
![]() |
Converts XML to JSON and JSON to XML | ![]() |
![]() |
![]() |
JSON Schema validation | ![]() |
![]() |
![]() |
JSON Schema generation from .NET types | ![]() |
![]() |
![]() |
Camel case JSON property names | ![]() |
![]() |
![]() |
Non-default constructors support | ![]() |
![]() |
![]() |
Serialization error handling | ![]() |
![]() |
![]() |
Supports populating an existing object | ![]() |
![]() |
![]() |
Efficiently serializes byte arrays as base64 text | ![]() |
![]() |
![]() |
Handles NaN, Infinity, -Infinity and undefined | ![]() |
![]() |
![]() |
Handles JavaScript constructors | ![]() |
![]() |
![]() |
Serializes .NET 4.0 dynamic objects | ![]() |
![]() |
![]() |
Serializes ISerializable objects | ![]() |
![]() |
![]() |
Supports serializing enums to their text name | ![]() |
![]() |
![]() |
JSON recursion limit support | ![]() |
![]() |
![]() |
Attribute property name customization | ![]() |
![]() |
![]() |
Attribute property order customization | ![]() |
![]() |
![]() |
Attribute property required customization | ![]() |
![]() |
![]() |
Supports ISO8601 dates | ![]() |
![]() |
![]() |
Supports JavaScript constructor dates | ![]() |
![]() |
![]() |
Supports Microsoft AJAX dates | ![]() |
![]() |
![]() |
Unquoted property names support | ![]() |
![]() |
![]() |
Raw JSON support | ![]() |
![]() |
![]() |
Supports reading and writing comments | ![]() |
![]() |
![]() |
Deserializes anonymous types | ![]() |
![]() |
![]() |
Opt-in property serialization | ![]() |
![]() |
![]() |
Opt-out property serialization | ![]() |
![]() |
![]() |
Efficiently stream reading and writing JSON | ![]() |
![]() |
![]() |
Single or double quote JSON content | ![]() |
![]() |
![]() |
Supports overriding a type's serialization | ![]() |
![]() |
![]() |
Supports OnDeserialized, OnSerializing, OnSerialized and OnDeserializing attributes | ![]() |
![]() |
![]() |
Supports serializing private properties | ![]() |
![]() |
![]() |
DataMember attribute support | ![]() |
![]() |
![]() |
MetdataType attribute support | ![]() |
![]() |
![]() |
DefaultValue attribute support | ![]() |
![]() |
![]() |
Serializes DataSets and DataTables | ![]() |
![]() |
![]() |
Serailizes Entity Framework | ![]() |
![]() |
![]() |
Serializes nHibernate | ![]() |
![]() |
![]() |
Case-insensitive property deserialization | ![]() |
![]() |
![]() |
分类:
Windows Phone
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述