Home >Web Front-end >JS Tutorial >Summary of methods for judging json in javascript_javascript skills
Simply put, JSON can convert a set of data represented in a JavaScript object into a string (pseudo-object), which can then be easily passed between functions or used in asynchronous applications. Passed from the Web client to the server-side program. This string looks a little weird (you'll see a few examples later), but JavaScript interprets it easily, and JSON can represent more complex structures than name/value pairs. For example, arrays and complex objects can be represented rather than just simple lists of keys and values.
Check whether json is empty
1. Determine whether json is empty
2. Determine whether the object is empty:
The third method is the simplest method, but the third method cannot be judged by the mutually exclusive method if (x). It can only be added in front of the object!
3. The json key cannot be repeated;
If it exists, it will be replaced, if it does not exist, it will be 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; return isjson; } if (!isJson(data)) data = eval('('+data+')');//将字符串转换成json格式
Structures in JSON: objects and arrays.
1. Object
An object starts with "{" and ends with "}". Each "key" is followed by a ":", and "'key/value' pairs" are separated by ",".
2. Array
An array is an ordered collection of values. An array starts with "[" and ends with "]". Use "," to separate values.
The above is the article introducing the judgment method of json in js. I hope you like it.