【发布时间】:2015-10-07 02:58:34
【问题描述】:
在使用json_decode 时,如果存在任何特殊字符,如“带黑钻的问号”,则解码返回空值。
我也使用过 UTF-8 编码。
【问题讨论】:
在使用json_decode 时,如果存在任何特殊字符,如“带黑钻的问号”,则解码返回空值。
我也使用过 UTF-8 编码。
【问题讨论】:
https://en.wikipedia.org/wiki/JSON#Data_portability_issues - 这就是你想要的? :) 尝试将其打印为 UTF 符号。
【讨论】:
您的问题似乎出在json_encode 部分而不是json_decode 部分。
看看这个: How to keep json_encode() from dropping strings with invalid characters
他们建议在您使用json_encode 之前使用iconv 字符串以确保删除所有非法字符。
引用给出的例子:
$stripped_of_invalid_utf8_chars_string = iconv('UTF-8', 'UTF-8//IGNORE', $orig_string);
if ($stripped_of_invalid_utf8_chars_string !== $orig_string) {
// one or more chars were invalid, and so they were stripped out.
// if you need to know where in the string the first stripped character was,
// then see https://stackoverflow.com/questions/7475437/find-first-character-that-is-different-between-two-strings
}
$json = json_encode($stripped_of_invalid_utf8_chars_string);
【讨论】: