Json.net 常用使用小结(推荐)

2019-05-22 15:45:02王冬梅

反序列化成数据字典Dictionary

Dictionary长度2
•key:key1,value:zhangsan
•key:key2,value:lisi

---------------------------------------------------------------

自定义反序列化

•当前List[x]对象类型:microstore.Employee
•FirstName:Maurice
•LastName:Moss
•BirthDate:1981-3-8 0:00:00
•Department:IT
•JobTitle:Support


•当前List[x]对象类型:microstore.Employee
•FirstName:Jen
•LastName:Barber
•BirthDate:1985-12-10 0:00:00
•Department:IT
•JobTitle:Manager

-------------------------------------------------------------

序列化输出的忽略特性
NullValueHandling特性忽略=>
{ "Name": "Bad Boys III", "Description": "It's no Bad Boys", "Classification": null, "Studio": null, "ReleaseDate": null, "ReleaseCountries": null }
{ "Name": "Bad Boys III", "Description": "It's no Bad Boys" }

属性标记忽略=>
{ "Model": "zhangsan", "Year": "2014-05-01T02:08:58.671875+08:00", "Features": [ "aaaa", "bbbb", "cccc" ] }
{ "Name": "zhangsan", "SalePrice": 3999.0 }
-----------------------------------------------------------------

Serializing Partial JSON Fragments
•Title:Paris Hilton - Wikipedia, the free encyclopedia
•Content: [1] In 2006, she released her debut album...
•Url:http://en.wikipedia.org/wiki/Paris_Hilton
•Title:Paris Hilton
•Content: Self: Zoolander. Socialite Paris Hilton...
•Url:http://www.imdb.com/name/nm0385296/

--------------------------------------------------------------------------------

ShouldSerialize
[ { "Name": "Joe Employee", "Manager": { "Name": "Mike Manager" } }, { "Name": "Mike Manager" } ]
{ "name": "Widget", "expiry": "2014-5-1 2:08:58", "price": 9.99, "sizes": [ "Small", "Medium", "Large" ] }

{ "channel": { "title": "James Newton-King", "link": "http://james.newtonking.com", "description": "James Newton-King's blog.", "item": [ { "title": "jewron", "description": "4546fds", "link": "http://www.baidu.com", "category": [ "j", "h", "g", "j" ] }, { "title": "jofdsn", "description": "mdsfan", "link": "http://www.baidu.com", "category": [ "6", "5", "4", "6" ] }, { "title": "jokjn", "description": "m3214an", "link": "http://www.baidu.com", "category": [ "h", "g", "4", "2", "5" ] }, { "title": "jon", "description": "man", "link": "http://www.baidu.com", "category": [ "g", "o", "o", "d", "m", "a", "n" ] } ] } }

以上这篇Json.net 常用使用小结(推荐)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易采站长站。