且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Json_encode,json_decode和UTF8

更新时间:2023-09-11 23:11:34

我从服务器获得的JSON响应中包含特殊字符.因此,我使用以下语句将其转换为UTF8,对JSON进行解码,并将其用作显示到UI的数组.

The JSON response I get from the server has special characters in it. So, I use the following statement to convert it to UTF8,decode the JSON and use it as an array to display to the UI.

JSON数据已经以UTF-8编码.您不应该再次将其转换为UTF-8.您将破坏数据.

JSON data already comes encoded in UTF-8. You shouldn't convert it to UTF-8 again; you'll corrupt the data.

代替此:

$response = json_decode(utf8_encode($jsonresponse));

您应该有这个:

$response = json_decode($jsonresponse); //already UTF-8!