R
R
Rolros2019-07-15 10:35:49
PHP
Rolros, 2019-07-15 10:35:49

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

The data all goes away and in the browser itself a sign flies out with the inscription Unexpected token in JSON at position 0
which points to the line
$result_contactID = $result_contactID['result']['0']['ID']; // РУГАЕТ JSON

How can I eliminate or mute this plate because the data is leaving and everything is working?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dima Pautov, 2019-07-15
@bootd

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

M
Mikhail Osher, 2019-07-15
@miraage

curl returns an error which is returned in html format.
check response status and content-type before doing anything

T
ThunderCat, 2019-07-15
@ThunderCat

...
$result_contactID = json_decode($result, 1);
var_dump($result_contactID);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question