print specific data from a json in php

0

I'm trying to make an application to get cnpj data in the federal revenue api. I can get and print all data via json, my problem is that I would like to print just a specific data, which in the case would be the email field, how can I do that?

Follow the api documentation link link

header("Content-Type: text/plain");
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://www.receitaws.com.br/v1/cnpj/" . $linha['cnpj']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$retorno = curl_exec($ch);
curl_close($ch);

$retorno = json_decode($retorno); //Ajuda a ser lido mais rapidamente
echo json_encode($retorno, JSON_PRETTY_PRINT);
    
asked by anonymous 09.05.2018 / 00:25

2 answers

1

Generally when not set CURLOPT_SSL_VERIFYPPER , usually gives error, then with this code you can get the data:

header("Content-Type: text/plain");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.receitaws.com.br/v1/cnpj/".$linha['cnpj']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
$retorno = curl_exec($ch);
curl_close($ch);
$retorno = json_decode($retorno);
echo $retorno->data_situacao;//aqui está um exemplo de um dado retornado da requisição
    
09.05.2018 / 13:31
0

$ email = $ return ['email']; So you get only the email.

You can manipulate Json any way you want to get any data. Just watch how structured it is. For example, the "text" in "core_activity" is inside a list, so it's a different approach to getting that field.

    
09.05.2018 / 13:26