我正在使用 Unirest PHP 调用 API。它看起来像这样:
$response = Unirest\Request::post(
"url_to_api",
array(
"api" => "my_api_key",
"Content-Type" => "application/json"
)
json_encode(array("parameters" => [100, 200]))
);
print_r($response->body);
响应正文包含很多信息。这是一个标准类对象。我该如何解析这个?我尝试像在 JSON 中那样解析它,但出现错误。响应如下所示:
stdClass Object ( [requestId] => blahblah [status] => Succeeded [elapsedTimeInMs] => 0 [warnings] => Array ( [0] => elapsedTimeInMs is deprecated. Please use the timing headers instead. [1] => status is deprecated. Please use HTTP status codes to determine the status of a request. ) [release] => stdClass Object ( [version] => 13 [commitId] => 275342fakeid5737425 [file] => test.R [function] => add_nums ) [result] => Array ( [0] => 300 ) )
我想要的只是响应中的 300,它发生在最后。