Introduction to JSON data source format

Source: Internet
Author: User
Tags string to json

JSON[JavaScript Object Notation]:JavaScript Object Notation.

It is a lightweight data exchange format.

 

JSON is more convenient as a data format than XML in many cases.

JSON data is composed of objects, arrays, and elements. Each format can contain valid JavaScript data types.

In JavaScript, strings can be directly converted to JSON format using the eval () method.

 

The JSON data source format is as follows:

Example 1:

   "Tablename":"Table Name",
      " Rows " : [ { " Column 1 " : " Value 1 " } , { " Column 2 " : " Value 2 " } . . . . . { " Column N " : " Value n " } ]  

Example 2:

 /* And JSON EquivalentCode
 VaR OBJ = New Object ();
 OBJ. createperson = Function (_ name, _ age ){
This. Name = _ Name;
This. Age = _ Age;
 }
 OBJ. getage = Function (){
Return This. Age;
 }
 */
 
VaR Person = {
"Createperson": Function(_ Name,_ Age){
This . name = _ name ;
 This.Age = _ Age;
  },
" getage " : function ( ) {
  Return This.Age;
   }
 };
 
 Person.Createperson("Xugang",20);
 VaR P = Person.Getage();
 Alert(P);

Example 3: convert a string to JSON using the eval () method and obtain the element value.

  <Script Type="Text/JavaScript">
  <!--
window . onload = function ( ) {
   VaR Json_text = "{ 'Book': {'name': 'java programmer', 'author': ['Liu ', 'xu']}, 'num': 222}";
   
   //Convert a string to an object using eval ()
      VaR   Json_obj   =   Eval ( " ( " +   Json_text   + " ) " ) ;
       
   //Access Book-Name
document . write ( json_obj . book . name ) ;
// access book-author-Xu
   Document.Write(Json_obj.Book.Author[1]);
  //-->
  </Script>

Appendix:The $. getjson () method is provided in jquery to quickly access the JSON data returned by the server.

From http://www.cnblogs.com/xugang/archive/2010/09/10/1823422.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.