Just testing found a simple, seemingly correct code that was wrong:
[PHP]View Plaincopy
- <?php
- $json _str = "{' name ': ' Eric ', ' age ': 23}";
- 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" >
- <?php
- $json _str = ' {' name ': ' Eric ', ' age ': 23,} ';
- $json _str = "{/" name/":/" eric/",/" age/": 23}"; That's fine.
- 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!