1.$json只能UTF-8編碼
//$json = mb_convert_encoding($json, 'utf8', 'gbk');
//$json = iconv('GBK', 'UTF-8//IGNORE', $json);
2.元素最後不能有逗號(與php的array不同)
3.元素不能使用單引號
$json = str_replace("'", '"', $json);
4.元素值中間不能有空格和n,必須替換
$json = str_replace(array("/r/n", "/r", "/n","/t"), "", $json);
5. 去掉bom頭
試了兩種方式能去除掉:
1
2
3
|
$result =
trim( $result ,
"\xEF\xBB\xBF" ); print_r(json_decode( $result ,
true)); exit ; |
還有一種比較矬:
1
2
3
4
5
|
$result =
@iconv( "UTF-8" ,
"GBK//IGNORE" ,
$result ); $result =
@iconv( "GBK" ,
"UTF-8//IGNORE" ,
$result ); print_r(json_decode( $result ,
true)); exit ; |