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

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

问题描述

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

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安装页面.而php 5.2中引入了json_encode/json_decode.因此,这可能是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天全站免登陆