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; }
}
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.