我该如何预先对此表示感谢?
angular.callbacks._1({"transaction":{"token":"Lf8jxwKp3XwSTIhpmOvFbJiHL4l","created_at":"2019-11-01T11:25:02Z","updated_at":"2019-11-01T11:25:02Z","succeeded":true,"transaction_type":"AddPaymentMethod","retained":false,"message":"Succeeded!","message_key":"messages.transaction_succeeded","payment_method":{"token":"58ta8FWrvwiPlEjnwDrUvzYJSir","data":null,"metadata":null,"storage_state":"cached","email":"Iokp@iephmail.com","created_at":"2019-11-01T11:25:02Z","updated_at":"2019-11-01T11:25:02Z","errors":[],"payment_method_type":"credit_card","first_name":"Mansio","last_name":"Enioms","full_name":"Fredrick Erispe","card_type":"visa","last_four_digits":"0373","first_six_digits":"446542","month":10,"year":2025,"address1":"1961 Timbercrest Road","address2":"","city":"MARCUS","state":"IL","zip":"51035","country":"US","phone_number":"18089648560","eligible_for_card_updater":true,"shipping_address1":null,"shipping_address2":null,"shipping_city":null,"shipping_state":null,"shipping_zip":null,"shipping_country":null,"shipping_phone_number":null,"company":null,"verification_value":"XXX","number":"XXXX-XXXX-XXXX-0373","fingerprint":"a84a3e186cc102c5621c59db43dbd8522d69"}},"status":201});
我的代码
$json= json_decode($data, true);
echo $transaction = $json['transaction']['payment_method'];
它什么也没显示,请帮助我。
答案 0 :(得分:0)
您没有得到任何结果,因为您的json无效。 Json_decode
函数仅接受有效的json。
赞:
<?php
$data = '{
"transaction": {
"token": "Lf8jxwKp3XwSTIhpmOvFbJiHL4l",
"created_at": "2019-11-01T11:25:02Z",
"updated_at": "2019-11-01T11:25:02Z",
"succeeded": true,
"transaction_type": "AddPaymentMethod",
"retained": false,
"message": "Succeeded!",
"message_key": "messages.transaction_succeeded",
"payment_method": {
"token": "58ta8FWrvwiPlEjnwDrUvzYJSir",
"data": null,
"metadata": null,
"storage_state": "cached",
"email": "Iokp@iephmail.com",
"created_at": "2019-11-01T11:25:02Z",
"updated_at": "2019-11-01T11:25:02Z",
"errors": [],
"payment_method_type": "credit_card",
"first_name": "Mansio",
"last_name": "Enioms",
"full_name": "Fredrick Erispe",
"card_type": "visa",
"last_four_digits": "0373",
"first_six_digits": "446542",
"month": 10,
"year": 2025,
"address1": "1961 Timbercrest Road",
"address2": "",
"city": "MARCUS",
"state": "IL",
"zip": "51035",
"country": "US",
"phone_number": "18089648560",
"eligible_for_card_updater": true,
"shipping_address1": null,
"shipping_address2": null,
"shipping_city": null,
"shipping_state": null,
"shipping_zip": null,
"shipping_country": null,
"shipping_phone_number": null,
"company": null,
"verification_value": "XXX",
"number": "XXXX-XXXX-XXXX-0373",
"fingerprint": "a84a3e186cc102c5621c59db43dbd8522d69"
}
},
"status": 201
}';
$json= json_decode($data, true);
print_r($json["transaction"]["payment_method"]);
输出将是:
Array
(
[token] => 58ta8FWrvwiPlEjnwDrUvzYJSir
[data] =>
[metadata] =>
[storage_state] => cached
[email] => Iokp@iephmail.com
[created_at] => 2019-11-01T11:25:02Z
[updated_at] => 2019-11-01T11:25:02Z
[errors] => Array
(
)
[payment_method_type] => credit_card
[first_name] => Mansio
[last_name] => Enioms
[full_name] => Fredrick Erispe
[card_type] => visa
[last_four_digits] => 0373
[first_six_digits] => 446542
[month] => 10
[year] => 2025
[address1] => 1961 Timbercrest Road
[address2] =>
[city] => MARCUS
[state] => IL
[zip] => 51035
[country] => US
[phone_number] => 18089648560
[eligible_for_card_updater] => 1
[shipping_address1] =>
[shipping_address2] =>
[shipping_city] =>
[shipping_state] =>
[shipping_zip] =>
[shipping_country] =>
[shipping_phone_number] =>
[company] =>
[verification_value] => XXX
[number] => XXXX-XXXX-XXXX-0373
[fingerprint] => a84a3e186cc102c5621c59db43dbd8522d69
)
注意:您的有效json位于angular.callbacks._1