So, I have an array I need to encode and send via an API.
$data = array(
'tracking_no' => $process_list->tracking_no,
'status' => $status_id
);
$data1 = (json_encode($data));
Now, I send it through curl to another site.
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => env('MILON_MELA_URL').'api/request/mm-process-data',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $data1,
CURLOPT_HTTPHEADER => array(
'ApiAuthorization: bearer '.$responsetoken->token,
'Content-Type: application/x-www-form-urlencoded'
),
));
$response1 = curl_exec($curl);
But for some reason, the result comes out as an array like this:
[{"tracking_no":"MM-43E9","status":"25"}]
Obviously, the function json_encode does not work here since the project thinks it is dealing with an array. So now we are stuck with a json_encoded string that thinks itself an array but cant be read. Now what? And yes, before anyone asks, I did search how to decode an array inside two brackets. It always leads me to multidimensional arrays which this is not..........