Home  >  Article  >  Backend Development  >  jons格式有关问题 如何数值型有带单引号如何去掉

jons格式有关问题 如何数值型有带单引号如何去掉

WBOY
WBOYOriginal
2016-06-13 12:26:12978browse

jons格式问题 怎么数值型有带单引号怎么去掉
怎么去掉单引号
$arr=array('as'=>1,'data'=>array('ID'=>$r_id,'List'=>$zfc));
echo json_encode($arr,JSON_FORCE_OBJECT);
{
    "as": 1,
    "data": {
        "ID": "111",
        "NeedImgList": "1.jpg,2.jpg"
    }
}

怎么把ID 中"111" 的双引号去掉???
------解决思路----------------------

$r_id = 111;<br />$zfc = '123';<br />$arr=array('as'=>1,'data'=>array('ID'=>$r_id,'List'=>$zfc));<br />echo json_encode($arr,JSON_FORCE_OBJECT <br><font color='#FF8000'>------解决思路----------------------</font><br> JSON_PRETTY_PRINT);
{<br />    "as": 1,<br />    "data": {<br />        "ID": 111,<br />        "List": "123"<br />    }<br />}<br />
可知 "111" 的双引号是你自己造成的(字符串)
这样写就没有了
$arr=array('as'=>1,'data'=>array('ID'=>intval($r_id),'List'=>$zfc));

------解决思路----------------------
因为是字符型,所以有引号,可以这样改。
<br />$arr=array('as'=>1,'data'=>array('ID'=>intval($r_id),'List'=>$zfc));<br />echo json_encode($arr,JSON_FORCE_OBJECT);<br />

------解决思路----------------------
<br /><br />$arr=array('as'=>1,'data'=>array('ID'=>$r_id+0,'List'=>$zfc));<br />echo json_encode($arr,JSON_FORCE_OBJECT);<br /><br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn