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.