小编ale*_*lot的帖子

json_decode 根据语言环境在 JSON 中重新格式化小数

我目前正在使用几种语言本地化的站点上工作,我遇到了一个问题,即 json_decode 正在根据语言环境重新格式化 JSON 字符串中的小数。当语言环境设置为“en”时,小数点保持不变。但是,例如,在“fr_FR”语言环境中,它们会更改为“13,3”。

源 JSON:

{"debug":[{"id":13.3}]}
Run Code Online (Sandbox Code Playgroud)

“en”的输出

Array
(
    [debug] => Array
        (
            [0] => Array
                (
                    [id] => 13.3
                )
        )
    )
Run Code Online (Sandbox Code Playgroud)

“fr_FR”的输出

Array
(
    [debug] => Array
        (
            [0] => Array
                (
                    [id] => 13,3
                )
        )
    )
Run Code Online (Sandbox Code Playgroud)

json_decode 有什么理由这样做吗?有什么办法可以预防吗?

该错误导致 Gravity Forms Wordpress 插件出现问题,但我已经将问题与 json_decode 函数隔离开来。

php wordpress json localization

4
推荐指数
1
解决办法
796
查看次数

标签 统计

json ×1

localization ×1

php ×1

wordpress ×1