Michael Voccola
Michael Voccola

Reputation: 1835

Encoding error passing JSON to PHP

A Dictionary is generated in Swift and converted to JSON to produce the following:

{"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"}

The JSON is then URL encoded and attached to a URL pointing at a PHP file. The encoded JSON is as follows:

%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, that decodes back into the original JSON. However, when echoing that from the PHP file using the following code where data is the passed param:

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

The returned JSON looks like this:

{\"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\"}

What is missing here that would generate this result?

Upvotes: 1

Views: 55

Answers (1)

Sougata Bose
Sougata Bose

Reputation: 31749

Try with -

echo stripslashes($json); 

Upvotes: 2

Related Questions