Home > Backend Development > PHP Tutorial > jons格式问题 怎么数值型有带单引号怎么去掉

jons格式问题 怎么数值型有带单引号怎么去掉

WBOY
Release: 2016-06-20 12:45:52
Original
1084 people have browsed it

怎么去掉单引号
$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" 的双引号去掉???


回复讨论(解决方案)

获取后再用replace函数去掉

$r_id = 111;$zfc = '123';$arr=array('as'=>1,'data'=>array('ID'=>$r_id,'List'=>$zfc));echo json_encode($arr,JSON_FORCE_OBJECT | JSON_PRETTY_PRINT);
Copy after login
{    "as": 1,    "data": {        "ID": 111,        "List": "123"    }}
Copy after login
可知 "111" 的双引号是你自己造成的(字符串)
这样写就没有了
$arr=array('as'=>1,'data'=>array('ID'=> intval($r_id),'List'=>$zfc));

因为是字符型,所以有引号,可以这样改。

$arr=array('as'=>1,'data'=>array('ID'=>intval($r_id),'List'=>$zfc));echo json_encode($arr,JSON_FORCE_OBJECT);
Copy after login

$arr=array('as'=>1,'data'=>array('ID'=>$r_id+0,'List'=>$zfc));echo json_encode($arr,JSON_FORCE_OBJECT);
Copy after login

解决了 谢谢各位大神!!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template