I have returned the response {\"status\":1,\"order-id\":\"8D0D3EEB-69D2-432D-9CDF-5ADCD42A00FC\",\"guest-checkout\":\"TRUE\",\"}
and i am trying to get Status.
public function test()
{
$apiurl = "****";
$data = [
'merchant-id' => $merchantId,
'api-key' => $apiKey,
];
$ch = curl_init($apiurl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$data = json_encode($result);
echo $data->status;
}
But when i do this data->status
, it returns empty. What could i be doing wrong here?
json_encode
returns a string, so you won't be able to access it as an object. If you want it as an object you will need to do something like this:
$data = json_decode(json_encode($result));
echo $data->status;
You might not even need to encode it, but without seeing the data that curl is returning I can't be sure.