Hi I have this simple string called $response1:
{"SN":"5054494EA805743F","MAC":"CC:19:A8:xx:xx:xx","customerName":"John doe ","id":"6666","serviceID":"1000","jobid":"12345"}
Essentially I get this string from a curl request but when I do
"$ree = json_decode($response1); print_r($ree); return null.
Here is the snippet
$response1 = curl_exec($ch2);
$ree = json_decode($response1);
print_r($dee);
print_r($response1);
JSON checkers says the string is okay, and json_last_error() returns 0
What is going on here ?
All the code as requested
<?php
$ch2 = curl_init();
//initiate http curl connection.
curl_setopt_array($ch2, array(
CURLOPT_URL => "http://x.x.x.x/Testingsomething.php",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"JobId\"\r\n\r\nXXXXXXX\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: multipart/form-data; boundary=----WebKitFormBoundaryXXXXXXXX",
),
));
//$response1 = curl_exec($ch2);
//$ree = json_decode($response1, true, JSON_THROW_ON_ERROR);
//print_r($ree);
//echo $ree["ontserial"];
try {
$response1 = curl_exec($ch2);
$ree = json_decode($response1, true, 512, JSON_THROW_ON_ERROR);
print_r($response1);
print_r($ree);
echo $ree;
}
catch (\JsonException $exception) {
echo $exception->getMessage(); // displays "Syntax error"
}