about what I do with JSON in my work.
First: Dynamic serialization classes
Second: Time format processing
Usually we have 10 or more properties in a class, but we usually only need to serialize three to five of them so there will be extra data.
If I just want to serialize ID with name how to handle
This is the method I am looking for online:
usingNewtonsoft.json;usingNewtonsoft.Json.Converters;usingNewtonsoft.Json.Serialization;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;namespacecyp.new.wcf.common.common{ Public classLimitpropscontractresolver:defaultcontractresolver {Private string[] props =NULL; PublicLimitpropscontractresolver (string[] props) { This. props =props; } protected OverrideIlist<jsonproperty>createproperties (Type type, Memberserialization memberserialization) {IList<JsonProperty> list =Base. Createproperties (type, memberserialization); //only the list of the listed sex is retained returnList. Where (p =props. Contains (P.propertyname)). ToList (); } }}
--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ----------------------------------------
About json.net processing date format look at the first picture. Json.NET Processing Date format This is not what normal human beings can see.
You might find that json.net has something to do with the date.
But this time you'll find that the json.net of the heavy load inside
Public Static stringSerializeObject (Objectvalue); Public Static stringSerializeObject (Objectvalue, formatting formatting); Public Static stringSerializeObject (Objectvalue, jsonserializersettings settings); Public Static stringSerializeObject (ObjectValueparamsjsonconverter[] converters); Public Static stringSerializeObject (Objectvalue, formatting formatting, jsonserializersettings settings); Public Static stringSerializeObject (ObjectValue, formatting formatting,paramsJsonconverter[] converters);
You will find that the dynamic serialization and the format of the time processing cannot coexist this problem really makes my little egg ache a bit ....
Solution:
usingNewtonsoft.json;usingNewtonsoft.Json.Converters;usingNewtonsoft.Json.Serialization;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;namespacecyp.new.wcf.common.common{ Public classLimitpropscontractresolver:defaultcontractresolver {Private string[] props =NULL; PublicLimitpropscontractresolver (string[] props) { This. props =props; } protected OverrideIlist<jsonproperty>createproperties (Type type, Memberserialization memberserialization) {IList<JsonProperty> list =Base. Createproperties (type, memberserialization); Isodatetimeconverter ISO=NewIsodatetimeconverter () {DateTimeFormat ="YYYY-MM-DD HH:mm:ss" }; IList<JsonProperty> Listwithconver =NewList<jsonproperty>(); foreach(varIteminchlist) { if(props. Contains (item. PropertyName)) {if(item. Propertytype.tostring (). Contains ("System.DateTime") {item. Converter=ISO; } listwithconver.add (item); } } returnListwithconver; } }}
Some handling of json.net
In a manner that is helpful to all
About Josn.net's http://www.codeplex.com/ -------------make by night, flowers clear light
Json.NET dynamic serialization and processing of time formats