【发布时间】:2021-05-31 01:08:34
【问题描述】:
在我的 Laravel-8 应用程序中,我将这个 api 作为 json:
api/tracking/{TrackerID}?sub-key=jkkmkf
看起来像:
api/tracking/19SB22?sub-key=jkkmkf
这是一个 GET 请求
当我尝试使用它时,如下所示,我收到了这个错误:
错误异常 未定义的偏移量:0
它指向这一行:
$当前 = $json[0];
我该如何解决这个问题?
谢谢
public function index() {
$request = Request::create('/api/tracking', 'GET');
$response = Route::dispatch($request);
$information = $response->content();
$json = json_decode($information, true);
$current = $json[0];
$geo = explode(',', $json[0]['current_asset_position_coord']);
return view('welcome', [
'current' => $current,
'json' => $json,
'geo' => $geo
]);
}
【问题讨论】: