Notes on the knowledge of the Jquery.parsejson () function (continuous update ... )

Source: Internet
Author: User
Tags control characters

JSON data may be very unfamiliar to me, but for me is semi-finished, because of project problems, do the web, although the use of JSON data format transmission, but about parsing this piece really do not know what to pay attention to, but also do not know how it is resolved, because recently to the serial communication protocol with this consistent, so, This afternoon specifically to understand the Jquery.parsejson () function of the relevant knowledge, here to do an excerpt, to become their own things.

1 . Strict JSON data format:

(1) If you want to correctly display the data you want on the Web page, only through the. Parsejson (jsonstring) function, the key is the parameters inside, that is, the JSON data format is correct or not:

(JSON requirements: Property names must be double quotes, if the corresponding property value is a string must also use double quotation marks, not allowed to be single quotes, that is, the so-called "well-formed"! )

If a malformed JSON string is passed in, a JS exception will be thrown: {id:1};

(2) In addition, the JSON standard does not allow "control characters", such as "\ T" and "\ n" in a string, to resolve such problems in a way that requires a reversal of the correct syntax, as follows:

$.parsejson (' {' name ': ' ysq\\txzh\\n '} ');

(3) The Parsejson () function belongs to the global jquery object;

(4) The return value of the Jquery.parsejson () function is any type that returns the representation of the JavaScript after parsing the specified JSON string.

(5) Examples of the use of jsonstring parameters are as follows:

01, var result1 = $.parsejson ("{}"); an empty object;

02. var result2 = $.parsejson (' {' name ': ' ysq ', ' Age ': 25} '); an object;

alert (result2.name); YSQ;

03, var RESULT3 = $.parsejson (' [1,true, ' ysq '] '); Object objects;

Alert (result3[2]); YSQ;

04, var RESULT4 = $.parsejson (' true '); Boolean value: TRUE;

05, var result5 = $.parsejson (' null '); Null

06, var result6 = $.parsejson (' 0 '); Integer: 0;

07, var result7 = $.parsejson (' Focus '); String value: Focus;

08, var result8 = $.parsejson ("\" focus \ ");//Ibid;

/********** The following are invalid JSON strings or unconventional parameter values ***********/

09, var result9 = $.parsejson (100);//1.9 returns NULL before, then returns 100;

010, var result10 = $.parsejson (1.23);//Ibid., return 1.23;

011, var result11 = $.parsejson (TRUE);//Ibid., returns true;

012, var result12 = $.parsejson (null);//return null;

013, var result13 = $.parsejson ("");//1.9 returns NULL before throwing an error;

014, var result14 = $.parsejson (undefined);//Ibid.

015, var result15 = $.parsejson ("undefined");//throws an error;

016, var result16 = $.parsejson ("12x;xx ' Invalid JSONx456");//Ibid.

017, var result17 = $.parsejson (' {name: "YSQ", age:1} ');//Ibid.

018, var result18 = $.parsejson (' {"name": \ ' ysq\ ', "Age": 1} ');//Ibid;

019, var result19 = $.parsejson (' {' name ': ' ysq\txzh\n '} ');//Ibid.

2. The parameter list of the Parsejson () function:(Continue tomorrow night)

Notes on the knowledge of the Jquery.parsejson () function (continuous update ... )

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.