如何从数组下面获取orderId?

时间:2018-08-28 10:05:02

标签: php

$ receipt数组给出以下输出。如何获取orderId?

pr($ data);死;

获取orderId,$ data ['receipt'] ['orderId'];但这给了我错误。.

App\Model\Entity\PaymentDetail Object
(
    [id] => 4
    [user_id] => 4
    [company_id] => 5
    [receipt] => {"orderId":"GPA.3312-5688-8401-53436","packageName":"com.kenbar.mynus2","productId":"com.mynus2.subscription99","purchaseTime":1534914306517,"purchaseState":0,"purchaseToken":"gefffblagdakjleamfngklli.AO-J1Ow9Q5PncOoRk-oshlRBQ8kVqt3A4uIZuQi6InX7sr4bx2lNzjS-VjOXyMIwkl2G-afrI0fzoVLEADNZP2RWekoxwe4ko1M884JALYhaZsxo44U9DshbKJxbDNQHcCx9_z0yQpxc","autoRenewing":true}

)

3 个答案:

答案 0 :(得分:2)

$orderJson = json_decode(data['receipt'],true);
print_r($orderJson['orderId']);

由于data['receipt']包含JSON字符串,因此您需要先将其解析为外部对象,然后再将其用作对象。

答案 1 :(得分:0)

您可以使用

$order_id = json_decode($data->reciept, true)["orderId"];

答案 2 :(得分:0)

$orderId=json_decode($your_array->receipt);


echo $orderId->orderId;

json对象字段中,您有一个stdClass作为字符串,因此您需要先对其进行解码,然后才能访问它。

上面的代码将为您服务。