php 顯示第二層 jsonObject 問題?

我可以用 $data->{'msg'} 印第一層的值,例如 msg
但假設我要印第二層我要怎麼寫?比如說我要印 card_info 的 bin_code

{
    "status": 0,
    "msg": "Success",
    "amount": 100,
    "acquirer": "xxx",
    "currency": "xxx",
    "rec_trade_id": "xxx",
    "bank_transaction_id": "xxx",
    "order_number": "",
    "auth_code": "xxx",
    "card_info": {
        "issuer": "JxxA",
        "funding": 0,
        "type": 1,
        "level": "",
        "country": "xx x",
        "last_four": "x",
        "bin_code": "x",
        "country_code": "x"
    },
    "transaction_time_millis": 1531387581490,
    "bank_transaction_time": {
        "start_time_millis": "1531387581528",
        "end_time_millis": "1531387581528"
    },
    "bank_result_code": "0",
    "bank_result_msg": ""
}

他不是 array,所以我的方式完全不行==

阅读 2.1k
1 个回答

你这个是json结构,解析成数组结构,再去获取。

$array = json_decode($json, true);
$bin_code = $array['card_info']['bin_code'];
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题