Source: http://www.cnblogs.com/mejozn/archive/2013/05/05/3060479.htmljson.net (Newtonsoft.json) is a popular, highly efficient Json serialization open source component in the. NET Framework that supports the. NET Framework 2.0 through 4.5 + and is available for. NET various environments Asp.net,silverlight,windows Phone,windows 8 and so on. http://json.codeplex.com/
Performance
Json.NET, DataContractJsonSerializer, javascriptseriallizer performance test results compared, not bad.
Reference
Mode 1: Download unzip reference Newtonsoft.Json.dll http://json.codeplex.com/releases/view/105633
Mode 2:nuget installation pm> install-package Newtonsoft.json
Serialization vs. deserialization
1. Basic usage first refers to the Newtonsoft.json namespace, which defines a class with JSON-like structure for conversion
New software{softid=1, softname="Limited time Free", downloadurl="/http" Itunes.apple.com/cn/app/id427577372?mt=8 ", releasetime=datetime.now };//serialized string Jsonstr = jsonconvert.serializeobject(software);//deserialization software objsoftware = Jsonconvert.deserializeobject<software>(JSONSTR); Console.WriteLine (JSONSTR);
Serialized output
2. Time format processing datetime type serialization default serialization as above, this format is difficult to read on other clients, or you want to format it by yourself
Newtonsoft.Json.Converters.IsoDateTimeConverter timeconverter = new Newtonsoft.Json.Converters.IsoDateTimeConverter (); Timeconverter.datetimeformat = "yyyy mm month DD day HH:MM:SS"; Console.WriteLine (Jsonconvert.serializeobject (software, timeconverter));
Output Result:
3. Anonymous type serialization This method can be deserialized without having to define a class with a JSON-like structure beforehand
JSON string@ "{result:-1,desc: ' parameter error, please check format '}"; Deserialization of Varjsonconvert.deserializeanonymoustypenew0string. Empty}); Console.WriteLine (String. Format ("result:{0} desc:{1}", Obj.result, Obj.desc));
4. Quick position node for fast processing or more complex JSON-structured strings, and do not want to define the corresponding transfer class
{"Weatherinfo": {"City": "Fuzhou", "city_en": "Fuzhou", "date_y": "May 4, 2013", "Date": "", "Week": "Saturday", "Fchh": "$", "Cityid" ":" 101230101 "," Temp1 ":" 16℃~21℃ "," Temp2 ":" 16℃~23℃ "," Temp3 ":" 17℃~24℃ "," Temp4 ":" 16℃~26℃ "," TEMP5 ":" 17℃~29℃ "," temp6 ":" 18℃~28℃ "," tempF1 ":" 60.8℉~69.8℉ "," tempF2 ":" 60.8℉~73.4℉ "," tempF3 ":" 62.6℉~75.2℉ "," tempF4 ":" 60.8℉~78.8℉ "," TempF5 ":" 62.6℉~84.2℉ "," tempF6 ":" 64.4℉~82.4℉ "," weather1 ":" Showers "," weather2 ":" Showers Turn cloudy "," Weather3 ":" Overcast to Thunderstorm "," Weather4 ":" Showers to thunderstorms "," weather5 ":" Showers Turn cloudy "," Weather6 ":" Cloudy to moderate Rain "," Img1 ":" 3 "," Img2 ":" "," IMG3 ":" 3 "," Img4 ":" 2 "," Img5 ":" 2 "," Img6 ":" 4 "," Img7 ":" 3 "," Img8 ":" 4 "," Img9 ":" 3 "," IMG10 ":" 1 "," img11 ": 1", "Img12": "8", "Img_single": "", " Img_title2 ":" Showers "," img_title3 ":" Showers "," img_title4 ":" Yin "," img_title5 ":" Yin "," img_title6 ":" Thunderstorm "," Img_title7 ":" Showers "," img _title8 ":" Thunderstorm "," img_title9 ":" Showers "," img_title10 ":" Cloudy "," Img_title11 ":" Cloudy "," img_title12 ":" Moderate Rain "," Img_title_single ":" Showers "," wind1 ":" Breeze "," wind2 ":" Breeze "," wind3 ":" Breeze "," Wind4 ":" Breeze "," Wind5 ":" Breeze "," Wind6 ":" Breeze "," fx1 ":" Breeze "," fx2 ":" Breeze "," FL1 ": "Less than 3 levels", "FL2": "Less than 3Level "," fl3 ":" Less than 3 levels "," FL4 ":" Less than 3 levels "," FL5 ":" Less than 3 levels "," fl6 ":" Less than 3 levels "," index ":" Comfortable "," index_d ":" Recommended for thin-type suits or denim shirt pants and other spring and autumn transition. " The frail and infirm are suitable for suits, jackets and so on. "," index48 ":" Comfortable "," index48_d ":" Recommended for thin-type suits or denim shirt pants and other spring and autumn transition. " The frail and infirm are suitable for suits, jackets and so on. "," INDEX_UV ":" Weak "," INDEX48_UV ":" Weakest "," INDEX_XC ":" Inappropriate "," INDEX_TR ":" Suitable "," index_co ":" Comfortable "," st1 ":" + "," St2 ":" + "," ST3 " : "St4": "+", "ST5": "Up", "St6": "+", "INDEX_CL": "Less suitable", "Index_ls": "Not Appropriate", "Index_ag": "Easy Hair"}
Read the Weather1 under Weatherinfo
var obj =jobject.parse(HTML); String Weather1 = (string) obj["Weatherinfo"["Weather1"];
Newtonsoft.json of. Net