JSON解码多级?

时间:2018-07-13 06:16:13

标签: php json

"links": [
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-1B56960729604235TKQQIYVY",
      "rel": "self",
      "method": "GET"
    },
    {
      "href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-60385559L1062554J",
      "rel": "approval_url",
      "method": "REDIRECT"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-1B56960729604235TKQQIYVY/execute",
      "rel": "execute",
      "method": "POST"
    }
  ]
}

这是我尝试过的:

$responseurl = json_decode($responseurl, true);
echo $responseurl["links"]["href"][0];

我尝试了多种组合方式,例如$responseurl["links"][0],但并没有运气,我真的希望有人可以帮助我,因为我有点卡住了!

非常感谢, 约翰

1 个答案:

答案 0 :(得分:4)

通过查看此处提供的json,从数组中的第一个元素访问href,应该像这样:

echo $responseurl["links"][0]["href"];