2013-10-21 106 views
-2

我綁到這個jsonString傳遞給我的查詢解碼JSON字符串解碼返回null

xxxxxx=createVenue&clientId=2&jsonString={"veneue":{"clientId":"b","name":"d","tagline":"f","phone":"b","address":"d","city":"f","state":"b","zip":"d","twitter":"f","license":"d","imagePath":"f","pickupLocation":"b"},"drinks":[{"type":"d","name":"f","servingTable":{"servingSize":"b","price":"d"}},{"type":"d","name":"f","servingTable":{"servingSize":"b","price":"d"}}],"spirits":[{"type":"d","name":"f","servingTable":{"servingSize":"b","price":"d"}},{"type":"d","name":"f","servingTable":{"servingSize":"b","price":"d"}}]} 

但是,當我在PHP解碼它返回null。

$clientId = trim($_REQUEST['clientId']); 
     $jsonString = trim($_REQUEST['jsonString']); 
     $decodedJSON = json_decode($jsonString); 

     return $decodedJSON; 

$ decodedJSON返回null;

出了什麼問題?

+0

你有沒有嘗試'urldecode()'之前''json_decode()'? –

+0

提示:*檢查* trim($ _ REQUEST ['jsonString'])'的值(並通過驗證程序運行以確定哪個部分現在無效) – user2864740

+0

什麼是投票的最低點? –

回答

3

您的JSON似乎有效。
由於您已啓用magic_quotes_gpc,因此可能會使用反斜槓進行引號轉義。你需要做的是使用

$jsonString = trim(stripslashes ($_REQUEST['jsonString'])); 
+0

修復它真的很感謝....簡單的請求是返回冒號變成斜槓。 –

+0

謝謝你的回答,找到它之後發現它像是2h一樣,這個問題是什麼......因爲它是輸入字段,所以引號被逃脫了。在調試過程中,您將如何看到這一點,以便我知道未來? –

1

解析嘗試產值像die(trim($_REQUEST['jsonString']));之前 - 你會看到字符串損壞

所以在此字符串插入網址到位的問題,在那個地方,你應該做urlencode(json_encode(...))