JS Operation JSON

Source: Internet
Author: User

1.1. Introduction to JSON 1.1.1. What is JSON

JSON (JavaScript Object Notation) is a lightweight data interchange format. It is based on a subset of JavaScript. The JSON value can be a number (integer or floating point), a string (in double quotes), a logical value (TRUE or false), Array (in square brackets), object (in curly braces), function , empty string , null

1.1.2. Structure of JSON

1.      object: Object in js "{}" {key : value, Key : value,...} key value object .key Gets the property value, the type of the property value can be A number, a string, an array, a few objects.

2. array: The array in JS is bracketed "[]" in the content, the data structure is ["java", " JavaScript "," VB ",...] , the value is obtained in the same way as in all languages, and the type of the field value can be Several types of numbers, strings, arrays, and objects.

1.2. JSON and string conversion 1.2.1. JSON converted to string

Json.stringify (Jsonobj)

1.2.2. String conversion to JSON

Varjsonstr = ' {' name ': ' Zhang San ', ' age ': 22} ';

Varjsonobj = eval ("(" +jsonstr+ ")");

1.3. JSON traversal

<scripttype= "Text/javascript" >

Varjsonobj = {"Name": "Zhang San", "Age": 22};

jsonobj.id=1;

for (var key in Jsonobj) {

Alert (key+ ":" +jsonobj[key])

}

</script>

JS Operation JSON

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.