How to get value from json type response in Laravel5

What you see is the object that response()->json() produces. That's not actually what the client will get. Because Laravel will convert it into a string before sending it back.

On the client you can just use it as JSON. Here's an example with jQuery ajax:

$.ajax({
    url: '/your/route'
}).done(function(data){
    alert(data.aa);  // alerts bbb
});

i have resolved the question,use getData() can read the json.

$a = response()->json(['aa'=>'bbb']);  
$a->getData()->aa;

In addition to what guanyue said:

$a = response()->json(['aa'=>'bbb'])->getData();  
dd($a->aa);

Its work!

Tags:

Php

Json

Laravel