我有以下数组:
Array
(
[BookDateID] => 4
[HotelName] => Adams’ Inn
)
输出:
{"BookDateID":"4","HotelName":null}
任何魔法?
BTW,我有一个替代解决方案,通过循环每个数组并让它们mb_convert_encoding(str,'HTML-ENTITIES')但我希望该字符保持不变,因为我必须将其插入DB。
foreach($array as $key=>$value){ $array[$key] = mb_convert_encoding($value,'HTML-ENTITIES'); }
答案 0 :(得分:2)
json_encode
需要UTF-8编码数据。确保数据是UTF-8编码的;目前它可能是Latin-1编码的。如何做到这一点取决于数据来自何处。阅读What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text和Handling Unicode Front To Back In A Web App。