带有json_decode的多维密钥对数组(Clickbank IPN v.6.0)

时间:2014-10-06 22:54:40

标签: json multidimensional-array clickbank

这是我从clickbank收到的即时付款通知(IPN)的示例:

$decrypted = {"transactionTime":"2014-10-06T14:49:00-07:00","receipt":"********","transactionType":"TEST","vendor":"comclub","role":"VENDOR","totalAccountAmount":1.00,"paymentMethod":"VISA","totalOrderAmount":1.00,"totalTaxAmount":0.00,"totalShippingAmount":0.00,"currency":"USD","lineItems":[{"itemNo":"1","productTitle":"A passed in title","shippable":false,"recurring":false,"accountAmount":1.00}],"customer":{"shipping":{"firstName":"TEST","lastName":"USER","fullName":"Test User","email":"testuser@somesite.com","address":{}},"billing":{"firstName":"TEST","lastName":"USER","fullName":"Test User","email":"testuser@somesite.com","address":{}}},"version":6.0,"attemptCount":1}

所以我做$order = json_decode($decrypted);

现在我想要取出各个变量。

起初,它运作正常。例如,我可以做

$transactionTime = $order->transactionTime;

但是当我使用lineItems获得第二级内容时,我感到很茫然。

我尝试了各种各样的事情:

$itemNo = $order['lineItems']['itemNo'];

$itemNo = $order['lineItems']->itemNo;

$lineItems = $order['lineItems'];
$itemNo = $lineItems['itemNo'];

但似乎没有任何效果。

我也试过

$order = json_decode($decrypted, TRUE);

但是那不起作用

有没有人知道如何获取itemNo变量?

感谢

1 个答案:

答案 0 :(得分:0)

您已将JSON解码为对象,因此您需要将其视为一个。

要访问lineItems,您需要$order->lineItems。您还应注意lineItems是一个对象数组并相应地处理它。例如$order->lineItems[0]->itemNo

Here's a demo.

将来,如果您不确定对象或数组的结构,请使用var_dump。它会对你有很大的帮助。