PHP and json how to print?

Asked

Viewed 99 times

1

1 answer

2


Use the function json_decode:

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


Minimal 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 EXAMPLE

References

Browser other questions tagged

You are not signed in. Login or sign up in order to post.