Unirest PHP和Mashape API响应

时间:2017-01-28 05:49:16

标签: php unirest mashape

我正在测试这个。这是我第一次与unirest和mashape。

代码:

<?
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;
?>

结果:

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

但是,我如何设置特定值('nome')到变量?

像这样:

MY NAME

1 个答案:

答案 0 :(得分:0)

试试这个

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