从多维Json解码数组中获取变量?

时间:2015-11-11 14:03:31

标签: php arrays json string multidimensional-array

我正在尝试找到客户使用的卡片类型。我正在测试:

$request_body = '{"id":8799347,"order_id":"1854059","accepted":true,"type":"Payment","text_on_statement":null,"branding_id":null,"variables":{},"currency":"USD","state":"new","operations":[{"id":1,"type":"authorize","amount":8996,"pending":false,"qp_status_code":"20000","qp_status_msg":"Approved","aq_status_code":"000","aq_status_msg":"Approved","data":{},"callback_url":"http://www.mywebsite.com/callback.php","callback_success":null,"callback_response_code":null,"created_at":"2015-11-11T11:08:40+00:00"}],"metadata":{"type":"card","brand":"visa","last4":"0008","exp_month":1,"exp_year":2019,"country":"US","is_3d_secure":false,"hash":"454545454878","number":null,"customer_ip":"1.1.2.23","customer_country":"US","fraud_suspected":false,"fraud_remarks":[]},"link":null,"shipping_address":null,"invoice_address":null,"test_mode":true,"acquirer":"via","facilitator":null,"created_at":"2015-11-11T11:08:34Z","balance":0}';

$request_array = json_decode($request_body, TRUE);

echo $request_array['brand']."<br />";

但是我觉得它出现在这里提到的多维数组中(http://www.dyn-web.com/tutorials/php-js/json/decode.php),我尝试过这个变种:

echo $request_array[1]['brand']."<br />"

echo $request_array[1]->brand."<br />"

但我无法获得品牌变量。

1 个答案:

答案 0 :(得分:0)

喔。

echo $request_array['metadata']['brand']."<br />";