Json. The essence is the key-value pair. is the serialization of the Web Effects object, a string that is an array. "JS, strings are objects, arrays are objects, classes are objects, everything is Object"
JSON (JavaScript Object notation) is a lightweight data interchange format. Easy for people to read and write, but also easy to machine parsing and generation. It is based on a subset of JavaScript (standard ecma-262 3rd edition-december 1999). JSON uses a completely language-independent text format, but it also uses a family of C-language (c, C + +, C #, Java, JavaScript, Perl, Python, and so on). These features make JSON an ideal data exchange language
<script>
function A () {
var str = "{" Error ":" Error Here!hello! "}";
var jsonobject = eval (' (' +str+ ') ');
alert (jsonobject.error);
}
</script>
<a onclick= "A ();" >test</a>
Let's look at a simple example
{date:1999-9-9,x:100,y:100}, [[' John ', ' 20 '],[' Dick ', ' 30 ']]; This is JSON. The essence is the key-value pair. is the serialization of a JavaScript object, a string that is an array. "JS, strings are objects, arrays are objects, classes are objects, everything is Object"
<script language= "JavaScript" >
var menu1 =
{
"A": {title: "1"},//in JS, the key value has no double quotes are indifferent, not wrong, grammar is so stipulated.
b:{"title": "2"},
C:{title: "3"},
D:{title:4}
}
alert (menu1.a.title);
for (var x in menu1)
{
document.write (x.tostring () + "</br>");
document.write (menu1[x].title+ "</br>");
document.write ("</br>==================</br>");
}
</script>
Okay, now it's time to provide a website.
String.prototype.parsejson = function () {try {return! /[^,:{}[]0-9.-+eaeflnr-u nrt]/.test (This.replace (/) (. | [^"]) *?" /g, ')) && eval (' (' + this + ') '); catch (e) {return false; }};