Answer the question
In order to leave comments, you need to log in
How to fix Unexpected token in JSON at position 0?
I have a code to send data via api
////////////////
$queryUrl = 'bitrix24.com/rest/1/id/crm.contact.list.json';
$queryData = http_build_query(array(
'filter' => array(
"PHONE" =>$data['telephone'],
),
'select' => array('ID')
));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $queryUrl,
CURLOPT_POSTFIELDS => $queryData,
));
$result = curl_exec($curl);
curl_close($curl);
$result_contactID = json_decode($result, 1);
$result_contactID = $result_contactID['result']['0']['ID']; // РУГАЕТ JSON
$result_contactID = $result_contactID['result']['0']['ID']; // РУГАЕТ JSON
Answer the question
In order to leave comments, you need to log in
An error in the JSON itself, either the quotes are not according to the canon, or it is missing somewhere, or there is an extra character somewhere, or they simply forgot to close the quote somewhere, or, in the very last property of the object, a comma crept in at the end. Print the data as a string and see what's inside
curl returns an error which is returned in html format.
check response status and content-type before doing anything
...
$result_contactID = json_decode($result, 1);
var_dump($result_contactID);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question