PHP and json how to print?

1

Could anyone help me print out each of these elements of this Json using php.

  

{"data": {"charges": [{"code": 30013193, "dueDate": "05/09/2017", "checkoutUrl": " link ", "link": "#

asked by anonymous 03.09.2017 / 04:25

1 answer

2

Use the json_decode function:

  

json_decode( string $string, bool $assoc_array = false )

Minimum example

  

$json = '{"data":{"charges":[{"code":30013193,"dueDate":"05/09/2017","checkoutUrl":"https://sandbox.boletobancario.com/boletofacil/checkout/985FFB59969D9F117D47FD7D1881880E", "link":"https://sandbox.boletobancario.com/boletofacil/charge/boleto.pdf?token=60370:m:9675cf45e010be056a06bdef6e0f478bd75f435ce9cda7d0cf5b9afdfc6fefc5","payNumber":"BOLETO TESTE"}]},"success":true}';

$value = (json_decode($json, true));

echo $value['data']['charges'][0]['code'];
echo PHP_EOL;
echo $value['data']['charges'][0]['dueDate'];
echo PHP_EOL;
echo $value['data']['charges'][0]['checkoutUrl'];
echo PHP_EOL;
echo $value['data']['charges'][0]['link'];
echo PHP_EOL;
echo $value['data']['charges'][0]['payNumber'];
echo PHP_EOL;
echo $value['success'];
echo PHP_EOL;

ONLINE Sample

03.09.2017 / 04:31