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