Json introduction:
JSON (JavaScript Object Notation) is a lightweight data exchange format. Easy for humans to read and write.
json official websitehttp://www.json.org/
json.net download addresshttp://json.codeplex.com/releases/view/37810
Demo:
Description:
After clicking the get button, the page will be requested, json data will be obtained, and filled into the table
html code:
Backend code:
public partial class json1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (HttpContext.Current.Request.QueryString[ "m"] != null)
{
List
Products = new List();
Products.Add(new Product() { Name = "Notebook", Price = " 4.2", Size = "30x50" });
Products.Add(new Product() { Name = "Ruler", Price = "1.2", Size = "30x50" });
Products.Add( new Product() { Name = "Book", Price = "36", Size = "30x50" });
Products.Add(new Product() { Name = "Pen", Price = "6.0", Size = "30x50" });
Products.Add(new Product() { Name = "Pencil", Price = "2.2", Size = "30x50" });
string json = JsonConvert.SerializeObject(Products );
Response.Write(json);
Response.End();
}
}
}
public class Product
{
public string Name { get; set; }
public string Size { get; set; }
public string Price { get; set; }
}
Knowledge points:
1. json officially provides a dll class library for .net operations. JsonConvert.SerializeObject serializes .net objects into json.
2.Javascript reads the json object var product = eval(callbackmsg).
3.Javascript reads the json value callbackmsg[u].Name.