I would like some help me before asking I've tried in several ways and it don't works
Here is the JSON response I get
{
"header": {
"api_version": "3.0.0",
"type_connection": 1,
"user": "",
"request_time": "2021-07-11 02:16:28",
"access_ip": null,
"error": null,
},
"result": [
{
"pessoa": ""{
"cadastral": ""{
"number": "41259288231",
"tipoLogradouro": "AVENIDA",
]
}}}]}
Here is the CURL
if (validNB($number)) {
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'localhost/cpf_json.php?token=235424343==&number='.$number.'',
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_ENCODING => 'gzip',
CURLOPT_HTTPHEADER => array(
'Accept-Encoding: gzip, deflate',
'Accept-Language: pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7',
'Cache-Control: no-cache',
'Connection: keep-alive',
'Pragma: no-cache',
'User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Mobile Safari/537.36'
),
));
echo $Procurar = curl_exec($ch);
$json = json_decode($Procurar, true);
sleep($SleepTime);
$gettime = $json[0]['header']['request_time'];
$checkerror = $json[0]['header']['error'];
$logra = $json[0]['pessoa']['cadastral']['tipoLogradouro'];
if($checkerror == null){
echo json_encode(array("status" => 1, "cartao" => 'Number: '.$number.' ', "separador" => '|',"retorno" => ' Test Get Time: '.$gettime.' | Test get error value: '.$checkerror.' test A error is null '));
} else {
echo json_encode(array("status" => 0, "cartao" => 'Number: '.$number.' ', "separador" => ' ', "retorno" => ' Test Get Time: '.$gettime.' | Test get error value: '.$checkerror.' test B Error is not null | test logra: '.$logra.' '));
}
Something is wrong.
If I access manually URL I can see the response correctly, but the value of my string is not being shown on echo.
Any idea how to solve it?
My if echo currently is:
{"status":1,"cartao":"Number: ","separador":"|","retorno":" Test Get Time: | Test get error value: test A "}
No strings value has printted
Thanks in advance
Edit:
I can't print string values on echo encode =( Before that, this code has already worked. Even without close curl, I just took what already worked and modified it to parse this JSON response Don't know why it's not working, the fact of it do not show string values make me believe that is something when I'm trying get values.
According to the structure of the obtained JSON response, would this syntax be wrong?
$gettime = $json[0]['header']['request_time'];
$checkerror = $json[0]['header']['error'];
$logra = $json[0]['pessoa']['cadastral']['tipoLogradouro'];
This would explain why I can't print the value
My Answer:
't answer that question without more context. Can you please provide more information or clarify your question?
Rate this post
4 of 5 based on 8011 votesComments