The string required by json_decode is strict:
- Use UTF-8 encoding
- Cannot have a comma in the last element
- Single quotes cannot be used
- There cannot be \r,\t, please replace if there are
Encounter problems:
Some editors will add the BOM header by default when returning the json string, which will cause the parsing to fail.
solution:
//解决返回的json字符串中返回了BOM头的不可见字符(某些编辑器默认会加上BOM头)
$result = trim($result,chr(239).chr(187).chr(191));
//解析json成数组
$array=json_decode($result,true);