Standard for JSON: double quotes rather than single quotes! __json

Source: Internet
Author: User

Just testing to find a simple, seemingly correct code is wrong:

<?php $json _str = "{' name ': ' Eric ', ' age ': 23}"; Var_dump (Json_decode ($json _str));

As you know, the PHP version has added two JSON-enabled functions since 5.2.0, Json_encode and Json_decode, where the Json_decode function converts the JSON string into a JSON object, as shown in the previous example. But the output of the example above is null, that is, the conversion failed. What is this, Baidu for a while, some people say that PHP is not the two functions of the JSON support of the complete cause, the solution is written in the following form:

<?php $json _str = ' {' name ': ' Eric ', ' age ': 23,} '; $json _str = "{/" name/":/" eric/",/" age/": 23}"; This is also done Var_dump (Json_decode ($json _str));

Just change the single quote to double quotes, but is this really a mistake in PHP? Then on the JSON website found that double quotes is the standard of JSON, single quotes is not standard (although in JS is the line of the pass). So you get into the habit of putting JSON names and string values in double 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.