Answer the question
In order to leave comments, you need to log in
Why is it impossible to process the parsed Json?
There is a url in which data is displayed in json format
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
print_r(json_decode($result))
var_dump($result); //string(26) "{"id":1,"bc":2,"asd":3}"
var_dump(json_decode($result)); //NULL
Answer the question
In order to leave comments, you need to log in
found a solution
// This will remove unwanted characters.
for ($i = 0; $i <= 31; ++$i) {
$result = str_replace(chr($i), "", $result);
}
$result = str_replace(chr(127), "", $result);
// This is the most common part
// Some file begins with 'efbbbf' to mark the beginning of the file. (binary level)
// here we detect it and we remove it, basically it's the first 3 characters
if (0 === strpos(bin2hex($result), 'efbbbf')) {
$result = substr($result, 3);
}
$result = json_decode( $result );
print_r($result);
** lied
Because the result of json_decode without the second parameter is an object, not an array.
Here json_decode($res, true) will return an array
In any incomprehensible situation with json
json_last_error ()
json decode still does not throw errors itself, it seems like they want to fix it, but someday maybe never)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question