当我们有 json_encode 时为什么要使用 CJSON 编码 [英] Why use CJSON encode when we have json_encode

查看:30
本文介绍了当我们有 json_encode 时为什么要使用 CJSON 编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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.

这篇关于当我们有 json_encode 时为什么要使用 CJSON 编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆