Parsing values from JSON using php -


i'm new php , json, hoping can me.

i have php 3rd party performs post against, delivering json data. example of data sent be:

> {   "created": 1326853478,   "livemode": false,   "id": > "evt_00000000000000",   "type": "charge.succeeded",   "object": > "event",   "data": { >     "object": { >       "id": "ch_00000000000000", >       "object": "charge", >       "created": 1366838716, >       "livemode": false, >       "paid": true, >       "amount": 1000, >       "currency": "gbp", >       "refunded": false, >       "fee": 59, >       "fee_details": [ >         { >           "amount": 59, >           "currency": "usd", >           "type": "stripe_fee", >           "description": "stripe processing fees", >           "application": null, >           "amount_refunded": 0 >         } >       ], >       "card": { >         "object": "card", >         "last4": "4242", >         "type": "visa", >         "exp_month": 2, >         "exp_year": 2016, >         "fingerprint": "cnijdyeew54ashw6iyr", >         "country": "us", >         "name": "wibble3", >         "address_line1": null, >         "address_line2": null, >         "address_city": null, >         "address_state": null, >         "address_zip": null, >         "address_country": null, >         "cvc_check": "pass", >         "address_line1_check": null, >         "address_zip_check": null >       }, >       "captured": true, >       "failure_message": null, >       "amount_refunded": 0, >       "customer": null, >       "invoice": null, >       "description": null, >       "dispute": null >     }   } } 

i able extract items process depending on these values.

using code, can extract 'type' enough:

$body = @file_get_contents('php://input'); $event_json = json_decode($body); print $event_json->{'type'}; 

but cannot extract "fee" example, seems level below extracting value from, or "description" level down again.

i able extract items json string (for example, type, fee, description, last4), lost. appreciate basic task, i'm getting no where.

any help, gratefully received!

first, suggest passing true second argument json_decode. results in associative array rather object, makes little easier work with.

then, can this:

$fee = $event_json['data']['object']['fee']; 

you can chain these square brackets many times needed delve deeper array.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -