我是使用PayPal API Express Checkout的新手,我有一个问题。 如何从paypal转换/获取响应值。这是我的回复字符串;
{" id":" PAY-XXXXXXXXXX72783PKXTZ4NI"," create_time":" 2015-09-03T01:11:17Z", " update_time":" 2015-09-03T01:12:21Z","州":"已批准","意图&# 34;:" sale"," payer":{" payment_method":" paypal"," payer_info":{ "电子邮件":" XXXXXXXXX-buyer@gmail.com"," first_name":" test"," last_name" :"买家"," payer_id":" PJ9LKYDVZXXXX"," shipping_address":{" line1":&#34 ; 1 Main St"," city":" San Jose"," state":" CA"," postal_code& #34;:" 95131"," country_code":" US"," recipient_name":" test buyer"交易":[{"金额":{"总计":" 700.00","货币&# 34;:" PHP","详细信息":{"小计":" 590.00","运费": " 110.00" }," description" ...
我希望得到这样的结果:
$ID = $response["id"];
$shipping_add_array = $response["shipping_address"];
echo $shipping_add_array["state"];
感谢您的帮助。我一周都没想到这个
答案 0 :(得分:3)
你很接近 - 添加json_decode():
$response = json_decode($paypal_response, true);
$ID = $response["id"];
要获得送货地址,您需要深入挖掘:
$shipping_add_array = $response["payer"]["payer_info"]["shipping_address"];
echo $shipping_add_array["state"];
您可以使用JSON格式化程序来帮助您找出对象的嵌套级别(更容易可视化嵌套的json数据) - 我发现的示例插件:(与开发人员没有任何关系)
chrome.google.com/webstore/detail/json-formatter/bcjindcccaagfpapjjmafapmmgkkhgoa?hl=en