JSON Standard: double quotes rather than single quotes!

Source: Internet
Author: User
Tags vars

Just testing found a simple, seemingly correct code that was wrong:

[PHP]View Plaincopy
    1. <?php
    2. $json _str = "{' name ': ' Eric ', ' age ': 23}";
    3. Var_dump (Json_decode ($json _str));

As you know, the PHP version has added two JSON-capable functions since 5.2.0, namely Json_encode and Json_decode, where the Json_decode function converts the JSON string to a JSON object, as shown in the previous example. But the output of the above example is null, that is, the conversion failed. This is why, Baidu, some people say that PHP's two functions of the JSON support is not completely caused by the solution is written in the following form:

[PHP]View Plaincopy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
    1. <?php
    2. $json _str = ' {' name ': ' Eric ', ' age ': 23,} ';
    3. $json _str = "{/" name/":/" eric/",/" age/": 23}"; That's fine.
    4. Var_dump (Json_decode ($json _str));

Just change the single quote to double quotes, but is this really a mistake for PHP? Then on the JSON official website found that the double quotation marks is the standard JSON, single quotation marks are not standard (although in JS is the line of the pass)! So everyone in the future to develop a habit, the name of the JSON and string values are quoted in double quotes ~

JSON official website: http://www.json.org/

Introduction to JSON: http://www.cnblogs.com/SkySoot/archive/2012/04/17/2453010.html

JSON Standard: double quotes rather than single quotes!

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.