Unirest PHP and Mashape API Response

447 Views Asked by At

i'm test this. Its my first time with unirest and mashape.

Code:

<?
require_once 'includes/unirest/Unirest.php';
$cpf = "MY CPF";
$response = Unirest\Request::get("https://consulta-situacao-cpf-cnpj.p.mashape.com/consultaSituacaoCPF?cpf=".$cpf,
  array(
    "X-Mashape-Key" => "MY SECRET KEY"
  )
);

echo $response->raw_body;
?>

Result:

{"nome":"MY NAME","situacaoCadastral":"CPF STATUS"}

But, how i set a especific value ('nome') to a variable?

Like this:

MY NAME
1

There are 1 best solutions below

2
shubham715 On

Try this

$getResponseVal = $response->raw_body;
$getDecodeData = json_decode($getResponseVal);
$getSpecificValue = $getSpecificValue['nome']; //this will assign nome value  to variable