The difference and conversion between JSON string and JSON object

Source: Internet
Author: User

A JSON object is a format that can be manipulated directly using jquery, and the object (class name) can be used to point out properties (methods), just as objects in JS do.

The JSON string is just a string, a whole, without intercepting the data stored in it, can not be used directly, unless you only want to alert () him;

JSON object:

var str2 = { "name": "haorooms", "sex": "man" };

JSON string:

var str1 = ‘{ "name": "haorooms", "sex": "man" }‘;
"JSON string" converted to "JSON object"

Please look at http://www.cnblogs.com/mawenqiangios/p/5186431.html.

Methods for reading JSON objects
var str2 = { "name": "haorooms", "sex": "man" };

You can read it like this:

alert(str2.name);//弹出” haorooms”。

The JSON we encounter is rarely so simple, such as a bit more complex JSON objects such as:

var str={"GetUserPostByIdResult":{"Age":"33","ID":"2server","Name":"haorooms"}};

Parsing by:

alert(str.GetUserPostByIdResult.Name); //弹出haorooms

This article is very simple, is a supplementary explanation of the previous articles! Only for Beginners!

The difference and conversion between JSON string and JSON object

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.