1. What's the JSON:
JSON refers to JavaScript Object notation (JavaScript object Notation),
JSON is a lightweight text data interchange format;
JSON is independent of language;
JSON is self-descriptive and easier to understand;
JSON uses JavaScript syntax to describe data objects, but JSON is still independent of languages and platforms, and JSON parsers and JSON libraries support many different programming languages.
2.json-convert to JavaScript object:
The JSON text format is syntactically identical to the code that creates the JavaScript object.
Therefore, without a parser, JavaScript programs can use the built-in eval () function to generate native JavaScript objects with JSON data.
3.json Syntax:
JSON syntax is a subset of the JavaScript Object notation syntax.
4.json format: Name/value pairs, name-value pairs include field names (in double quotes), followed by a colon, and then a value
JSON object: {"FirstName": "John", "LastName": "Doe"}
JSON array: {"Employees": [{"Flrstname": "John", "LastName": "Doe", "FirstName": "Anna", "LastName": "Smith"}]}
Convert 5.json text to JavaScript objects:
The JavaScript function eval () can be used to convert the JSON text to a JavaScript object.
var txt = ' {' Employees ': [ ' + ' {' firstName ': ' Bill ', ' lastName ': ' Gates '}, ' + ' {' firstName ': ' George ', ' lastName ":" Bush "}, ' + ' {" FirstName ":" Thomas "," LastName ":" Carter "}]} '
;
var obj=eval (' (' +txt+ ') ');
<script type= "Etxt/javascript" >
document.getElementById (' fname '). Innerhtml=obj.employees[1].firstname;
document.getElementById (' lname '). Innerhtml=obj.employees[1].lastname;
</script>
(Outside a JSON ' employees ', inside is an array, the inside of the array is JSON,)
6.json Read
1.var json={name: ' Miaov ', Age:23,fun: ' Web '}
for (Var sttr in JSON) {
alert (attr);
}
2.var json={' name ': ' Miaov ', ' age ': $, ' fun ': ' Web '}
for (Var sttr in JSON) {
Alert (json[attr]);
}
JS Note--json