我想把这个json String传递给我的查询
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;
$ decoding JSON返回null;
有什么问题?
答案 0 :(得分:3)
你的json似乎有效。
由于你启用了magic_quotes_gpc,引号可能会被反斜杠转义。你需要做的是使用
$jsonString = trim(stripslashes ($_REQUEST['jsonString']));
答案 1 :(得分:1)
在解析之前尝试输出像die(trim($_REQUEST['jsonString']));
这样的值 - 你会看到字符串已损坏
因此将此字符串插入到网址中的问题,在那个地方您应该urlencode(json_encode(...))