To use. NET comes with a JSON processing tool that needs to reference the following namespaces:
Using System.Web.Script.Serialization;
1. Encoding
New myconfig (); " Test " ; " it's good. " ; New JavaScriptSerializer (); object result = json. Serialize (MC); Response.Write (result);
2. Decoding
// the custom class will use the following Public class Myconfig { publicstringgetset;} Public string Get Set ; } }
1>. Simple decoding
string " {config: ' latest engine ', info: ' I think it's the best '} " ; New JavaScriptSerializer (); = json. deserialize<myconfig>(str); " -- " + mc.info);
2>. Complex decoding
stringstr ="[{config: ' engine ', info: ' Best '},{config: ' displacement ', info: ' 2.5cc '}]"; JavaScriptSerializer JSON=NewJavaScriptSerializer (); //list<myconfig> result = (list<myconfig>) JSON. Deserialize<list<myconfig>> (str); //function Ibid .list<myconfig> result = (list<myconfig>) JSON. Deserialize (str,typeof(list<myconfig>)); foreach(varIteminchresult) {Response.Write (Item.config+"--"+ Item.info +"<br/>"); }
Asp. The processing of JSON in net