In depth understanding of the JSON data source format

  • 2020-03-30 01:16:41
  • OfStack

JSON [JavaScript Object Notation] : JavaScript Object Notation.

It is a lightweight data interchange format.

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

JSON data consists of objects, arrays, elements, and so on. Each format can contain valid JavaScript data types.

In JavaScript, you can convert a string directly to JSON via the eval() method.

JSON data source format is as follows:

Example 1:

   "tablename":" The name of the table ", 
   "rows":[{" column 1":" value 1"},{" column 2":" value 2"}.....{" column n":" value n"}]  

Example 2:


var person = { 
"createPerson": function(_name,_age){ 
        = _name; 
                 this.age = _age; 
 "getAge": function(){ 
              return this.age; 

 var p = person.getAge(); 

Example 3: the eval() method converts a string directly to JSON and gets the value of the element.

  <script type="text/javascript"> 
    window.onload = function(){ 
       var json_text = "{ 'book':{'name':'JAVA programming ','author':['Liu','Xu']},'num':222}"; 

       //Use eval() to convert a string to an object
       var json_obj = eval("("+ json_text +")"); 

       //Access to the book - the name
       //Access to the book - the author - Xu

Note: the $.getjson () method is provided in JQuery for quick access to JSON data returned from the server side.

Related articles: