how to get json data in different veriables in laravel?

i am getting response in return response()->json(['data' => $res]);

array:2 [▼
  "response" => "{"ResCode":"TPB013","ResMsg":"Invalid BAR code, please refresh","ResStatus":1,"sign":"w0EQNoxIOkl0K3IKZYKJEPojBrHerRwdTHS4fhAz3n9CxfIprH0QklzgdNaWWzwmBUq++h2U43 ▶"
  "http_code" => 200
]
{#576 ▼
  +"ResCode": "TPB013"
  +"ResMsg": "Invalid BAR code, please refresh"
  +"ResStatus": 1
  +"sign": "w0EQNoxIOkl0K3IKZYKJEPojBrHerRwdTHS4fhAz3n9CxfIprH0QklzgdNaWWzwmBUq++h2U432d4s5uHmCTjA=="
}

i want that i get all the response in different veriables like this
$responcse = //json res
$http_code = //json res
$ResCode   = //json res
$ResMsg    = //json res
$ResStatus = //json res
$sign      = //json res

how i can do that in laravel i dont know how to handle json response

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Use php’s extract function:

$response["test"] = 123;
extract($response);
var_dump($test);

Method 2

This should be basic PHP, using json_decode you can get each value.

$data = json_decode($res['response']);

$data = // response
$res['http_code'] = // http_code
$data->ResCode 
$data->ResMsg
$data->ResStatus
$data->sign


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x