Simply put, JSON converts a set of data represented in a JavaScript object to a string (pseudo object), which can then be easily passed between functions, or pass a string from a WEB client to a server-side program in an asynchronous application. This string looks a little odd (see some examples later), but JavaScript is easy to explain, and JSON can represent a more complex structure than name/value pairs. For example, you can represent arrays and complex objects, not just simple lists of keys and values.
To determine if JSON is empty
Copy Code code as follows:
1, to determine whether the JSON is empty
Copy Code code as follows:
2, determine whether the object is empty:
Copy Code code as follows:
if (typeOf (x) = = "undefined")
if (typeOf (x)!= "Object")
if (!x)
The third is the simplest method, but the third one cannot be judged by a mutually exclusive method of if (x), only in front of the object.
3, JSON key can not be repeated;
Copy Code code as follows:
exists in the substitution, does not exist is added.
4. Traverse JSON
for (var key in jsonstr) {
alert (key+ "+jsonstr[key])
}
Isjson = function (obj) {
var Isjson = typeof (obj) = = "Object" && Object.prototype.toString.call (obj). toLowerCase () = = "[Object Object]" &&!obj.length;< C5/>return Isjson;
}
if (!isjson (data)) data = eval (' (' +data+ ') ');//convert string to JSON format
Structure in JSON: objects and arrays.
1. The object
An object ends with "{" Beginning, "}". Each "key" is followed by a ":", "Key/value" to "use", "separated."
Copy Code code as follows:
Packjson = {"Name": "Nikita", "Password": "1111"}
2. Array
Copy Code code as follows:
Packjson = [{"Name": "Nikita", "Password": "1111"}, {"Name": "Tony", "Password": "2222"}];
An array is an ordered collection of values. An array ends with "[" Beginning, "]". Values are separated by ",".
The above is the introduction of JS JSON in the judgment method, I hope you like.