Home > Enterprise >  how to get json data in different veriables in laravel?
how to get json data in different veriables in laravel?

Time:09-16

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

CodePudding user response:

Use php's extract function:

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

CodePudding user response:

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
  • Related