【笔记】处理 PHP 的 JSON_encode 函数中文转义和反斜杠问题

php ⋅ tytrock ⋅ at 2022-09-12 17:48:12 ⋅ 5253 Reads

在使用php的json_encode方法对数据进行JSON编码时,会自动将中文进行转义和在斜杠前面加上反斜杠,如下图所示:

image.png


解决方法一:

json_encode($data, JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES)

解决方法二:

str_replace("\\/", "/", json_encode($res, JSON_UNESCAPED_UNICODE))


This topic has been mark as Excenllent Topic.
Total Reply Count: 0
    No comments~~
    • publish_typography
    • publish_markdown
    • 支持表情,使用方法请见 Emoji 自动补全来咯,可用的 Emoji 请见 :metal: :point_right: Emoji 列表 :star: :sparkles:
    • publish_image
    • publish_draft
    Ctrl+Enter