<span style= "color: #3333FF;" > </span><span style= "color: #3333FF;" >public void ProcessRequest (HttpContext context)
{
Context. Response.ContentType = "Text/plain";
--Building JSON format data
String Jsonarr = "{' Id ':", ' Name ': ' Zhangsan '} ";//---1th data
String Jsonarr = "[{' id ': 1, ' name ': ' Zhang San ', ' age ': ' 20},{' id ': 2, ' name ': ' John Doe ', ' Age ': '}]";//---2nd data
Context. Response.Write (JSON);
list<people> Listperson = new list<people> ();
People person = new people ();
Person. Id = 1;
Person. Name = "Zhang San";
Person. Age = 20;
Listperson. ADD (person);
JavaScriptSerializer JSS = new JavaScriptSerializer ();//implement encapsulation of JSON data with the Javascriptserialize class
String json = JSS. Serialize (Listperson);//---The 3rd kind of data
Context. Response.Write (JSON);
}
class people
{
public int Id {get; set;}
public string Name {get; set;}
public int Age {get; set;}
}
</span>
<span style= "color: #3333FF;" > <script src= "/js/jquery-1.4.2.js" type= "Text/javascript" ></SCRIPT>
<script type= "text/ JavaScript "
$ (function () {
$.post ("/jsondata.ashx ", {}, function (data) {
/*
JSON is generally used in a small amount of data processing. Because the format is simple, operation aspect, and JS natively supports the processing function of JSON format
JSON general format is as follows: {"id": 1, "name": "Zhangsan"} or [{"id": 1, "name": "Zhangsan"},{"id": 2 , "Name": "Lisi"}] multidimensional array
*/
/*
JS Parsing json Format method "Personal method, there are more analytic methods online Check"
★eval (' (' +json+ ') ')
★jquery.parsejson (JSON)
*/
if (data! = NULL) {
/*
★eval (' (' +json+ ') ')
var Evaljson = eval (' (' + data + ‘)‘);
//"{' Id ': ' Name ': ' Zhangsan '}";//---"1th data in C # code"
//$ ("#spanJson"). HTML (Evaljson. Id + "-" + Evaljson. Name); The case and definition are identical
for (var i = 0; i < evaljson.length; i++) {//process multidimensional JSON---"2nd data in C # code"
$ ("#spanJson"). Append (Ev Aljson[i]. Id + "-" + evaljson[i]. Name+ "-" +evaljson[i]. Age+ "<br/>");
}
*/
/*★jquery.parsejson (JSON) */
var Parsej = $.parsejson (data);
for (var i = 0; i < parsej.length; i++) {//process multidimensional JSON "corresponds to 3rd data in C # code"
$ ("#spanJson"). Append (Parsej[i]. Id + "-" + parsej[i]. Name + "-" + parsej[i]. Age + "<br/>");
}
}
});
});
</script></span>
Ajax get methods to display JSON data