将JSON传递给PHP的编码错误

时间:2015-02-03 05:05:53

标签: php json

在Swift中生成一个字典并转换为JSON以生成以下内容:

{"recordId":"1184","category":"Audio","qtyInStock":"1","itemId":"54","itemName":"100.16.4 Snake","make":"LiveWire","plShared":"1","description":"100' 16-channel, 4-return audio","subcategory":"Snake","barcode":"54","showInResults":"1"}

然后对JSON进行URL编码并将其附加到指向PHP文件的URL。编码的JSON如下:

%7B%22recordId%22:%221517%22,%22category%22:%22Audio%22,%22qtyInStock%22:%221%22,%22itemId%22:%221698%22,%22itemName%22:%22ADAPT-XLRM%22,%22make%22:%22StudioHub%22,%22plShared%22:%22%22,%22description%22:%22%22,%22subcategory%22:%22Adapter%22,%22barcode%22:%221698%22,%22showInResults%22:%22%22%7D

According to this site,解码回原始的JSON。但是,当使用以下代码在PHP文件中回显它时data是传递的参数:

$json = $_GET['data'];
echo $json;

返回的JSON如下所示:

{\"recordId\":\"1184\",\"category\":\"Audio\",\"qtyInStock\":\"1\",\"itemId\":\"54\",\"itemName\":\"100.16.4 Snake\",\"make\":\"LiveWire\",\"plShared\":\"1\",\"description\":\"100\' 16-channel, 4-return audio\",\"subcategory\":\"Snake\",\"barcode\":\"54\",\"showInResults\":\"1\"}

这里会遗漏什么会产生这个结果?

1 个答案:

答案 0 :(得分:2)

尝试 -

echo stripslashes($json);