JSON分隔变量

时间:2013-08-01 21:08:50

标签: php json

我有以下代码,通过JSON输出。

stdClass Object
(
    [event_type] => transaction.created
    [event_resource] => stdClass Object
        (
            [id] => tran_9x2x8xex5x7xexex0x8x9xexexbx
            [amount] => 9980
            [origin_amount] => 9980
            [status] => open
            [description] => 9xax1x7x5x8x2xaxaxcx4x5xfx8x2x2x
            [livemode] => 1
            [refunds] =>
            [currency] => GBP
            [created_at] => 1375307922
            [updated_at] => 1375307922
            [response_code] => 10001
            [short_id] =>
            [is_fraud] =>
            [invoices] => Array
                (
                )

            [app_id] =>
            [fees] => Array
                (
                )

            [payment] => stdClass Object
                (
                    [id] => pay_7xdxex9xfxcx6x3x9x5x7xcx
                    [type] => creditcard
                    [client] => client_2x2xex0x2x4xx3bx3x6x
                    [card_type] => mastercard
                    [country] =>
                    [expire_month] => 10
                    [expire_year] => 2015
                    [card_holder] => XXX XXXXXX
                    [last4] => 8XX8
                    [created_at] => 1375307921
                    [updated_at] => 1375307922
                    [app_id] =>
                )

            [client] => stdClass Object
                (
                    [id] => client_2x2xex0x2x4xfx3x3x6x
                    [email] =>
                    [description] =>
                    [created_at] => 1375307922
                    [updated_at] => 1375307922
                    [app_id] =>
                    [payment] => Array
                        (
                        )

                    [subscription] =>
                )

            [preauthorization] =>
        )

    [created_at] => 1375307922
    [app_id] =>
)


Event Rosource ID = tran_9x2x8xex5x7xexex0x8x9xexexbx

我需要能够接受每个变量并将其称为简单的变量,例如

$ eventresourceid = tran_9x2x8xex5x7xexex0x8x9xexexbx

$ eventresourceamount = 9980

谁能告诉我怎么做呢?

1 个答案:

答案 0 :(得分:1)

使用$obj->event_resource->id$obj->event_resource->amount