How to remove single quotation marks for the numeric type in jons format?-php Tutorial

Source: Internet
Author: User
Question about jons format how to remove single quotation marks for a numeric type
$ 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"
}
}

How can I remove the double quotation marks "111" from the ID ???


Reply to discussion (solution)

Use the replace function to remove it.

$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);
{    "as": 1,    "data": {        "ID": 111,        "List": "123"    }}
We can see that the double quotation marks of "111" are your own (string)
In this way, the writing will be gone.
$ Arr = array ('as' => 1, 'data' => array ('id' => intval ($ r_id), 'list' => $ zfc ));

Because it is character type, there are quotation marks, you can change it like this.

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

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

Thank you !!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.