在使用json_decode
时,如果存在任何特殊字符,例如“带黑钻石的问号”,则解码将返回空值。
我也使用过UTF-8编码。
答案 0 :(得分:0)
您的问题似乎在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);
答案 1 :(得分:0)
https://en.wikipedia.org/wiki/JSON#Data_portability_issues - 这就是你想要的? :)尝试将其打印为UTF符号。