print specific data of a json in php

Asked

Viewed 139 times

0

I’m trying to make an application to get the data from cnpj in the IRS api. I can bring and print all the data via json, my problem is that I would like to print only one specific data, which in case would be the email field, how can I do this ?

Follow the api documentation link https://receitaws.com.br/api

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);
  • If possible attach echo’s return, so the community can help you.

2 answers

1

Usually when not defined CURLOPT_SSL_VERIFYPPER, it’s usually a mistake, so 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

0

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

You can handle Json however you want to get any data. Just consider how it is structured. For example the "text" in "activity_main" is within a list, so it’s a different approach to get this field.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.