In depth understanding of the JSON data source format


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){
                 this.name = _name;
                 this.age = _age;
              },
 "getAge": function(){
              return this.age;
           }
 };

 person.createPerson("xugang",20);
 var p = person.getAge();
 alert(p);

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
       document.write(json_obj.book.name);
       //Access to the book - the author - Xu
       document.write(json_obj.book.author[1]);
    } 
  //-->
  </script>

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