如何在我的代码点火器视图中显示 JSON 输出?



我正在使用 Rapidapi 进行 smole 项目机场搜索,但 我无法在我的代码点火器视图中显示来自 API 的 JSON 数据。我正在谷歌搜索我的任何时间,但不是完美的结果。请帮忙

这是我的 JSON 输出

HttpResponse Object
(
[code:HttpResponse:private] => 200
[raw_body:HttpResponse:private] => [{"airportId":"6f576bf7-090a-46e3-be70-6d8a55275e04","code":"YYZ","name":"Toronto, Ontario","location":{"longitude":-79.63083299999998,"latitude":43.677222},"cityId":"8f65ce90-aafb-42b4-8185-ae4f1b131889","city":"Toronto","countryCode":"CA","themes":[],"pointsOfSale":["CA"]}]
[body:HttpResponse:private] => Array
(
[0] => stdClass Object
(
[airportId] => 6f576bf7-090a-46e3-be70-6d8a55275e04
[code] => YYZ
[name] => Toronto, Ontario
[location] => stdClass Object
(
[longitude] => -79.630833
[latitude] => 43.677222
)
[cityId] => 8f65ce90-aafb-42b4-8185-ae4f1b131889
[city] => Toronto
[countryCode] => CA
[themes] => Array
(
)
[pointsOfSale] => Array
(
[0] => CA
)
)
)

)

我的控制器

public function AirportSearch_form(){
$url="https://cometari-airportsfinder-v1.p.rapidapi.com/api/airports/by-code?code=yyz";
$response = $this->unirest->get($url, $headers = array("X-Mashape-Key" => "ced348bae5mshd648601c9de77cbp1e2dcejsn222973a7564d", "X-Mashape-Host" => "cometari-airportsfinder-v1.p.rapidapi.com"));
//echo'<pre>';
//print_r($response);
//exit();
$jdata=json_decode($response);
$app_title=$this->SuperAdmin_model->AppDataShow();
$data['title']=$app_title->app_title;
$data['menu_col']='';
$this->load->view('agent/header',$data);
$this->load->view('flight/airport_search',$jdata);
$this->load->view('agent/footer',$data);
}

您检索了 JSON 和非 JSON 版本。 由于后者不需要解码,我建议您使用它。

似乎您可以执行$response->body[0]来获取数组。

以及通过$response->body[0]->name等的特定项目。

最新更新