Home > Web Front-end > JS Tutorial > In-depth understanding of JSON data source format_javascript skills

In-depth understanding of JSON data source format_javascript skills

WBOY
Release: 2016-05-16 17:04:27
Original
1516 people have browsed it

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 situations.

JSON data consists of objects, arrays, elements and other formats. Each format can contain legal JavaScript data types.

In JavaScript, you can directly convert a string into JSON format through the eval() method.

JSON data source format is as follows:

Example 1:

Copy code The code is as follows:

{
"tablename ":"Table name",
"rows":[{"Column 1":"Value 1"},{"Column 2":"Value 2"}....{"Column n":" Value n"}]
}

Example 2:
Copy code The code is as follows:

/* Code equivalent to JSON
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; (p);


Example 3: Use the eval() method to directly convert the string into JSON and obtain the value of the element.




Copy code


The code is as follows:
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