-2

我想将此 jsonString 传递给我的查询

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 返回空值;

怎么了 ?

4

2 回答 2

3

你的 json 似乎是有效的。
引号可能会用反斜杠转义,因为您打开了 magic_quotes_gpc。你需要做的是使用

$jsonString = trim(stripslashes ($_REQUEST['jsonString']));
于 2013-10-21T17:23:58.837 回答
1

在解析之前尝试输出值die(trim($_REQUEST['jsonString']));- 你会看到该字符串已损坏

所以这个字符串插入到url的地方有问题,在那个地方你应该做urlencode(json_encode(...))

于 2013-10-21T17:15:47.433 回答