Conversion and Value Method of json strings in the json array of the json object in javascript, javascriptjson

Source: Internet
Author: User

Conversion and Value Method of json strings in the json array of the json object in javascript, javascriptjson

The conversion and value between the json array and the json object and the json string are used today. record the following:

1. convert a json string to a json object and its values

Var jsonString = '{"bar": "property", "baz": 3}'; var jsObject = JSON. parse (jsonString); // convert to the json object alert (jsObject. bar); // obtain the value in json

2. convert a json object to a json string

Var jsonString = '{"bar": "property", "baz": 3}'; var jsObject = JSON. parse (jsonString); // convert to the json object alert (jsObject. bar); // obtain the value var st = json in JSON. stringify (jsObject); // convert to a json string

3. convert a json array string to json and convert a value from a json object to a json string.

// Json array string value var jsonStr = '[{"id": "01", "open": false, "pId": "0", "name ": "Department A" },{ "id": "01", "open": false, "pId": "0", "name": "department "}, {"id": "011", "open": false, "pId": "01", "name": "department A" },{ "id ": "03", "open": false, "pId": "0", "name": "department A" },{ "id": "04 ", "open": false, "pId": "0", "name": "department A" },{ "id": "05", "open": false, "pId": "0", "name": "department A" },{ "id": "06", "open": false, "pId ": "0", "name": "department A"}] '; var jsonObj = JSON. parse (jsonStr); // convert to the json object for (var I = 0; I <jsonObj. length; I ++) {alert (jsonObj [I]. id); // get the value in json} console. log (jsonObj) var jsonStr1 = JSON. stringify (jsonObj) console. log (jsonStr1 + "jsonStr1 ")

Result:

The preceding section describes the conversion and value methods of json arrays of json objects in javascript. I hope this will be helpful to you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.