Ad

How To Read JsonResponse In Php

How to get id from here

JsonResponse {#457 ▼
  #data: "{"bill":{"id":11,"invoice_no":"9m36r9_1459170388239"}}"
  #callback: null
}

I am getting this output from this laravel code

return Response::json($response);

I tried json_decode but not worked here, a blank output is coming.

Thanks for any help.

Ad

Answer

Try like this

$jsonResponse = Response::json([
        'id' => 1,
        'test' => 'test'
    ]);

$content = $jsonResponse->getContent();
$array = json_decode($content, true);
$id = $array['id']
Ad
source: stackoverflow.com
Ad