尝试通过PHP中的JSON发送URL时遇到问题

Amr*_*ngh 2 php json

我正在使用PHP的Android应用程序的Web服务.我正在尝试使用JSON中的其他数据发送URL.但是URL发送的数据会在URL中显示不需要的斜杠(//).

这是我正在使用的代码:

if(isset($_POST['category_id'])):

        $result=$db->sub_category($_POST['category_id']);
        if($result):
        $msg="Success";
        $arr = array();
        while($row=mysql_fetch_array($result)):
            $arr['response'][] = array('category' => $row['category'], 'image' => "http://intelmobizsolution.com/Iphone/upload/iphone/".$row['image'], 'msg'=>$msg,'status'=>true); 
        endwhile;
        $abc=json_encode($arr);
        echo json_encode($arr);
        endif;


endif;
Run Code Online (Sandbox Code Playgroud)

但结果显示如下:

{"response":[{"category":"Administrative Support2","image":"http:\/\/intelmobizsolution.com\/Iphone\/upload\/iphone\/27792582102banner_02.jpg","msg":"Success","status":true}]} 
Run Code Online (Sandbox Code Playgroud)

如何以我想要的格式发送带有JSON的URL?

Que*_*tin 6

最好的方法是接受斜杠.他们绝对没有伤害.将它们转义为JSON字符串是完全可以接受的.

如果你真的想摆脱它们,那么你可以使用:

json_encode($arr, JSON_UNESCAPED_SLASHES);
Run Code Online (Sandbox Code Playgroud)

...但是如果您的数据包含字符串</script>并且您将JSON输出到HTML文档中的某些JavaScript中,那么您将破坏您的脚本.