Home > Web Front-end > JS Tutorial > body text

json introductory study notes sample code_json

WBOY
Release: 2016-05-16 18:29:53
Original
1131 people have browsed it

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:

 json introductory study notes sample code_json

Description:
After clicking the get button, the page will be requested, json data will be obtained, and filled into the table
html code:

Copy code The code is as follows:






















Name

Price

Size



< ;/html>

Backend code:
Copy code The code is as follows:

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.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template