如果原始数据与其他名称具有相同的名称字符串,则如何回显

时间:2019-07-05 09:48:18

标签: php curl

我从网上商店收到此POST响应,但是Raw Data有2个TOKEN字符串,我只想回显TOKEN表单payment_method,我的问题将是什么PHP代码? 而且如果我想从“事务”中打印“消息”,那么代码将是什么?我已经尝试过通过互联网搜索,但是我很难找出答案

这是原始数据

{
    "transaction": {
        "token": "TWN0rD9euove3BEUNRs0PPv2s9w", // this it the token that i dont want to echo
        "created_at": "2019-07-05T09:34:21Z",
        "updated_at": "2019-07-05T09:34:22Z",
        "succeeded": true,
        "transaction_type": "AddPaymentMethod",
        "retained": false,
        "state": "succeeded",
        "message_key": "messages.transaction_succeeded",
        "message": "Succeeded!",
        "payment_method": {
            "token": "BXtwsBABZ2z15DkyN5dbTWrwakV",  //This is the token that i need to echo
            "created_at": "2019-07-05T09:34:21Z",
            "updated_at": "2019-07-05T09:34:22Z",
            "email": "testemail@gmail.com",
            "data": null,
            "storage_state": "cached",
            "test": false,
            "metadata": null,
            "callback_url": null,
            "last_four_digits": "4242",
            "first_six_digits": "424242",
            "card_type": "visa",
            "first_name": "First",
            "last_name": "Last",
            "month": 6,
            "year": 2022,
            "address1": null,
            "address2": null,
            "city": null,
            "state": null,
            "zip": "1000",
            "country": null,
            "phone_number": null,
            "company": null,
            "full_name": "Test Test",
            "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,
            "payment_method_type": "credit_card",
            "errors": [],
            "fingerprint": "eeebce09a3bf9fba352df975a5c999998",
            "verification_value": "XXX",
            "number": "XXXX-XXXX-XXXX-4242"
        }
    } }

1 个答案:

答案 0 :(得分:1)

您可以将json_decode与true一起用作第二个参数,以将其转换为数组,

echo 'token: '.$arr['transaction']['payment_method']['token']."\n";
echo 'message: '.$arr['transaction']['message'];

Demo
输出

token: BXtwsBABZ2z15DkyN5dbTWrwakV
message: Succeeded!
相关问题