Any way to return PHP json_encode with encode UTF-8 and not Unicode?

$arr=array('a'=>'á');
echo json_encode($arr);

mb_internal_encoding('UTF-8');$arr=array_map('utf8_encode',$arr);不能解决这个问题.

结果:{"a":"\u00e1"}

Expected result: 100

推荐答案

{"a":"\u00e1"} and {"a":"á"} are different ways to write the same JSON document; The JSON decoder will decode the unicode escape.

In php 5.4+, php's json_encode does have the JSON_UNESCAPED_UNICODE option for plain output. On older php versions, you can roll out your own JSON encoder that does not encode non-ASCII characters, or use Pear's JSON encoder and remove line 349 to 433.

Json相关问答推荐

使用Jolt v.0.1.1向每个json元素添加一个键-值对

如何在Vega中使标记的符号在鼠标指针悬停时可点击

如何将响应数据保存到Flutter 中的共享首选项中

VBA json按特定属性名称提取所有数据

当由.sh脚本执行时,AWS查询字符串不会提取任何数据

将 std::可选值存储到 json 文件 C++

转换为Json时忽略内部对象中的数组

使用本地 JSON api react TS Axios

为什么根据其他工具,来自 aws rds 的 JSON 在 Docker 中格式错误运行?

JOLT 转换 - 删除 JSON 数组中的空 node

JSON 模式实际用于什么目的?

如何将任意 json 对象发布到 webapi

为什么我不能在 C# 中引用 System.Runtime.Serialization.Json

了解 JSON Schema 草稿版本 4 中的additionalProperties关键字

如何使用 Jackson 重命名 JSON 序列化中的根键

为不同类型的项目数组正确的 JSON Schema

有没有办法在 angular.json 中扩展配置?

如何转换为 D3 的 JSON 格式?

严重:找不到媒体类型 = 应用程序/json、类型 = 类 com.jersey.jaxb.Todo、通用类型 = 类 com.jersey.jaxb.Todo 的 MessageBodyWriter

如何使用 SwiftyJSON 遍历 JSON?