The summary of JSON judgment in JS (continuous finishing in ~)

Source: Internet
Author: User
Tags convert string to json string to json

"Determine if JSON is empty"

var jsonstr ={};

1. Determine if the JSON is empty

Jquery.isemptyobject ();

2. Determine if the object is empty:

1, if (typeOf (x) = = "undefined")

2, if (TYPEOF (x)! = "Object")

3. if (!x)

The third is the simplest method, but the third one can not be used if (x) this mutually exclusive method to judge, only in front of the object to add!

3. The key of JSON cannot be duplicated;

jsonstr[key]= "XXX", which exists in substitution, does not exist is added.

4. Traverse JSON

for (var key in Jsonstr) {

Alert (key+ "" +jsonstr[key])

}

" determines whether the return JSON format "

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+ ') ');//convert string to JSON format

Summary of JSON judgments in

JS (continuous finishing)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.