当我们有 json_encode 时为什么要使用 CJSON 编码

2022-01-04 00:00:00 json php yii

我正在使用 Yii 为网站构建 API.我知道有一个名为 CJson 的实用程序类,并且有一个名为 encode 的函数.

I am building an API for a website using Yii. I know that there is a utility class called CJson and has a function called encode.

据我所知,还有一些额外的参数可以在原生 json_encode 函数中进行自定义,比如 JSON_NUMERIC_CHECK,这非常有用.它创造了

As far as I know there are additional parameters that can be customized in the native json_encode function like the JSON_NUMERIC_CHECK which is really useful. It creates

{
    "id": 17
}

而不是 Yii 的 CJSON 编码,它使 '17' 成为一个字符串.

instead of Yii's CJSON encode which makes the '17' a string.

{
    "id": "17"
}

所以我的问题是是否有任何理由我应该使用 CJSON 编码而不是内置的 PHP 函数 json_encode ?

So my question is whether there is any reason I should use CJSON encode instead of the built in PHP function json_encode ?

推荐答案

我能想到的只有最低 php 版本支持.

Only thing I can think minimum php version support.

Yii 支持 php 5.1 作为最低版本,请参阅 Yii 安装页面.而 json_encode/json_decode 在 php 5.2 中引入.所以这可能是 Yii 拥有 CJson 库的一个原因.

Yii support php 5.1 as minimum version See Yii Installation Page . While json_encode/json_decode introduced in php 5.2. So It can be a reason for Yii having a library for CJson.

相关文章