In the use of Json_decode JSON format string decoding is empty, page blank Ah, the whole half-day check here to check there, ask colleagues are useless.
Bing search today, the problem solved, originally there is a BOM head output , prawn solution is as follows:
1), Json_decode ($json, Boolean): $json is a JSON-formatted character, the second parameter is true when the conversion is an array, and the default false indicates
Convert to an object.
2), Json_decode Required string comparison is strict:
(1) Use UTF-8 Code (2) cannot have comma (3) in the last element cannot use single quotation mark (4) cannot have \r,\t, if please replace
Solution One:
So here's the problem. Returns the invisible character of the BOM header in the returned JSON string, some editors default to the BOM header, and the following processing is required to correctly parse the JSON data:
<?php$info = json_decode(trim($info,chr(239).chr(187).chr(191)),true);
方法二:在转为json之前对中文进行转码
functionArrayrecursive (&$array,$function,$apply _to_keys_also=false){ Static $recursive _counter= 0; if(++$recursive _counter>1000 ) { die(' Possible deep recursion attack '); } foreach($array as $key=$value) { if(Is_array($value) {arrayrecursive ($array[$key],$function,$apply _to_keys_also); } Else { $array[$key] =$function($value); } if($apply _to_keys_also&&is_string($key)) { $new _key=$function($key); if($new _key!=$key) { $array[$new _key] =$array[$key]; unset($array[$key]); } } } $recursive _counter--;}/************************************************************** * * Convert an array to a JSON string (Chinese language compatible) * @param array $array to be converted * @return string converted to JSON string * @access public * *************************************************************/functionJSON ($array) {arrayrecursive ($array, ' UrlEncode ',true); $json= Json_encode ($array); return UrlDecode($json);}EchoJSON ($user);View Code
Reprint Address: https://segmentfault.com/q/1010000002991973
There is also a description of the details: http://www.cnblogs.com/xcxc/p/3729207.html
PHP get JSON json_decode return null workaround