I want to remove special chars (and found this in a forum):
$response = trim(preg_replace("#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|([\s\t]//.*)|(^//.*)#", '', $response));
The same for this
for ($i = 0; $i <= 31; ++$i) {
$response = str_replace(chr($i), "", $response);
}
$response = str_replace(chr(127), "", $response);
if (0 === strpos(bin2hex($response), 'efbbbf')) {
$response = substr($response, 3);
}
And this for encoding
$response = mb_convert_encoding($response, "UTF-8");
echo "\nJSON Response:#$response#\n";
At this point $response echoes:
{"data":{"taxa":[{"placa":"EDY8986","taxas_detran":"141.36","seguro_dpvat":"211.30","ipva":"1945.20","multas":"5048.10","total_debitos":"null"}]},"code":200,"pagination":{"rows":1,"page":1,"pages":0,"hasNext":false,"totalRows":1}}
In the end
$data = json_decode('"' . $response . '"',true, 512);
echo "\n\nData>\n";
print_r($data);
echo "\nError> "; echo json_last_error_msg();
json_last_error_msg() prints:
Syntax Error
I've already validated it in JSONLint and JSON Formatter and it is valid.
$data = json_decode($response,true, 512);