JSON编码显示意外的shashes

时间:2017-04-06 10:54:59

标签: php json

当我对数据进行编码时,它会添加意外的斜杠。

这是数据

 ""\"\\\"[{\\\\\\\"PropertyId\\\\\\\":\\\\\\\"544068\\\\\\\",\\\\\\\"FloorplanId\\\\\\\":\\\\\\\"2175341\\\\\\\",\\\\\\\"FloorplanName\\\\\\\":\\\\\\\"50 Regent 1AP\\\\\\\",\\\\\\\"Beds\\\\\\\":\\\\\\\"1\\\\\\\",\\\\\\\"Baths\\\\\\\":\\\\\\\"1.00\\\\\\\",\\\\\\\"MinimumSQFT\\\\\\\":\\\\\\\"667\\\\\\\",\\\\\\\"MaximumSQFT\\\\\\\":\\\\\\\"667\\\\\\\",\\\\\\\"MinimumRent\\\\\\\":\\\\\\\"2475\\\\\\\",\\\\\\\"MaximumRent\\\\\\\":\\\\\\\"2475\\\\\\\",\\\\\\\"MinimumDeposit\\\\\\\":\\\\\\\"0\\\\\\\",\\\\\\\"MaximumDeposit\\\\\\\":\\\\\\\"0\\\\\\\",\\\\\\\"AvailableUnitsCount\\\\\\\":\\\\\\\"1\\\\\\\",\\\\\\\"AvailabilityURL\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"FloorplanImageURL\\\\\\\":\\\\\\\"http:\\\\\\\\\\\\\\\/\\\\\\\\\\\\\\\/cdn.rentcafe.com\\\\\\\\\\\\\\\/dmslivecafe\\\\\\\\\\\\\\\/3\\\\\\\\\\\\\\\/544068\\\\\\\\\\\\\\\/50Reg1AP.jpg\\\\\\\",\\\\\\\"FloorplanImageName\\\\\\\":\\\\\\\"50Reg1AP.jpg\\\\\\\",\\\\\\\"PropertyShowsSpecials\\\\\\\":\\\\\\\"0\\\\\\\",\\\\\\\"FloorplanHasSpecials\\\\\\\":\\\\\\\"0\\\\\\\",\\\\\\\"UnitTypeMapping\\\\\\\":\\\\\\\"0050r1ap\\\\\\\"}]\\\"\"""

2 个答案:

答案 0 :(得分:-1)

尝试

json_encode($data, JSON_UNESCAPED_SLASHES);

答案 1 :(得分:-1)

试试这个

<?php
function removeslashes($string)
{
    $string=implode("",explode("\\",$string));
    return stripslashes(trim($string));
}

/* Example */

$text="""\"\\\"[{\\\\\\\"PropertyId\\\\\\\":\\\\\\\"544068\\\\\\\",\\\\\\\"FloorplanId\\\\\\\":\\\\\\\"2175341\\\\\\\",\\\\\\\"FloorplanName\\\\\\\":\\\\\\\"50 Regent 1AP\\\\\\\",\\\\\\\"Beds\\\\\\\":\\\\\\\"1\\\\\\\",\\\\\\\"Baths\\\\\\\":\\\\\\\"1.00\\\\\\\",\\\\\\\"MinimumSQFT\\\\\\\":\\\\\\\"667\\\\\\\",\\\\\\\"MaximumSQFT\\\\\\\":\\\\\\\"667\\\\\\\",\\\\\\\"MinimumRent\\\\\\\":\\\\\\\"2475\\\\\\\",\\\\\\\"MaximumRent\\\\\\\":\\\\\\\"2475\\\\\\\",\\\\\\\"MinimumDeposit\\\\\\\":\\\\\\\"0\\\\\\\",\\\\\\\"MaximumDeposit\\\\\\\":\\\\\\\"0\\\\\\\",\\\\\\\"AvailableUnitsCount\\\\\\\":\\\\\\\"1\\\\\\\",\\\\\\\"AvailabilityURL\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"FloorplanImageURL\\\\\\\":\\\\\\\"http:\\\\\\\\\\\\\\\/\\\\\\\\\\\\\\\/cdn.rentcafe.com\\\\\\\\\\\\\\\/dmslivecafe\\\\\\\\\\\\\\\/3\\\\\\\\\\\\\\\/544068\\\\\\\\\\\\\\\/50Reg1AP.jpg\\\\\\\",\\\\\\\"FloorplanImageName\\\\\\\":\\\\\\\"50Reg1AP.jpg\\\\\\\",\\\\\\\"PropertyShowsSpecials\\\\\\\":\\\\\\\"0\\\\\\\",\\\\\\\"FloorplanHasSpecials\\\\\\\":\\\\\\\"0\\\\\\\",\\\\\\\"UnitTypeMapping\\\\\\\":\\\\\\\"0050r1ap\\\\\\\"}]\\\"\"""";
echo removeslashes($text);
?>