0

作为测试,此 JSON 数据正在发布到我的网站:

{
    "order": {
        "id": null,
        "created_at": null,
        "status": "new",
        "total_btc": {
            "cents": 100000000,
            "currency_iso": "BTC"
        },
        "total_native": {
            "cents": 2263,
            "currency_iso": "USD"
        },
        "custom": "123456789",
        "button": {
            "type": "buy_now",
            "name": "Test Item",
            "description": null,
            "id": null
        },
        "transaction": {
            "hash": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
            "confirmations": 0
        }
    }
}

由于它是从服务器到服务器发送的,因此我看不到数据。我尝试将 $_POST 数组发送到文本文件,但它出现空白。我认为我需要做的是:

$data = json_decode($jsonData);

但是如何设置变量 $jsonData?

4

3 回答 3

3

您可以尝试使用包装器来读取原始 POST 查询。

$data = file_get_contents("php://input");
于 2013-02-09T05:46:30.757 回答
0

您是否尝试过,将获得的字符串存储到变量中然后对其进行解码?

$postedJsonData= '{"order":{"id":null,"created_at":null,"status":"new","total_btc":
{"cents":100000000,"currency_iso":"BTC"},"total_native":
{"cents":2263,"currency_iso":"USD"},"custom":"123456789","button":
{"type":"buy_now","name":"Test Item","description":null,"id":null},"transaction":
{"hash":"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b","confirmations":0}}}';

var_dump(json_decode($postedJsonData, true));

true 参数将返回一个关联数组

于 2013-02-09T05:43:17.037 回答
0

$data = json_decode($jsonData, True);

于 2013-02-09T05:43:52.957 回答