我在请求通过此处的两条经纬度路线时收到了一些杂乱无章的文本 api
I got some unorganized texts while requesting the route of two lat long through here api
我正在使用此处的 rest api v7 地理编码和搜索 api 并且 url 是 https://route.ls.hereapi.com/routing/7.2/calculateroute.json?apiKey=[here api 键]&waypoint0=geo!22.578765 ,88.295014&waypoint1=geo!22.570253,88.301865&routeattributes=wp,sm,sh,sc&mode=fastest;car
但是当我尝试使用邮递员并使用 google chrome 进行正常搜索时,它会给我预期的 json return 但是当我尝试使用 curl 通过 codeigniter 请求它首先给我一些无组织的文本然后它 return 响应 json。所以我需要得到与 json 的距离。但由于首先出现的是无组织的数据,我无法跟踪它......
这是我在 codeigniter 中使用的代码。
function shipcalculate(){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://route.ls.hereapi.com/routing/7.2/calculateroute.json?apiKey=[here api key]&waypoint0=geo!22.578765,88.295014&waypoint1=geo!22.570253,88.301865&routeattributes=wp,sm,sh,sc&mode=fastest;car",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
//print_r(json_decode(json_encode($response)));
//print_r(json_decode($response)) ;
}
输出时间为
但我想获得标准 json 格式的输出。
请帮帮我......
好的我明白了....
$newresponse = json_decode($response);
$array = json_decode(json_encode($newresponse), true);
echo $array['response']['route'][0]['summary']['distance'];
我在 curl close 后添加了这三行,我得到了距离。另外,我现在明白为什么要发短信了,发短信是因为 JSON 回复中有 HTML。
我正在使用此处的 rest api v7 地理编码和搜索 api 并且 url 是 https://route.ls.hereapi.com/routing/7.2/calculateroute.json?apiKey=[here api 键]&waypoint0=geo!22.578765 ,88.295014&waypoint1=geo!22.570253,88.301865&routeattributes=wp,sm,sh,sc&mode=fastest;car 但是当我尝试使用邮递员并使用 google chrome 进行正常搜索时,它会给我预期的 json return 但是当我尝试使用 curl 通过 codeigniter 请求它首先给我一些无组织的文本然后它 return 响应 json。所以我需要得到与 json 的距离。但由于首先出现的是无组织的数据,我无法跟踪它...... 这是我在 codeigniter 中使用的代码。
function shipcalculate(){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://route.ls.hereapi.com/routing/7.2/calculateroute.json?apiKey=[here api key]&waypoint0=geo!22.578765,88.295014&waypoint1=geo!22.570253,88.301865&routeattributes=wp,sm,sh,sc&mode=fastest;car",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
//print_r(json_decode(json_encode($response)));
//print_r(json_decode($response)) ;
}
输出时间为
但我想获得标准 json 格式的输出。
请帮帮我......
好的我明白了....
$newresponse = json_decode($response);
$array = json_decode(json_encode($newresponse), true);
echo $array['response']['route'][0]['summary']['distance'];
我在 curl close 后添加了这三行,我得到了距离。另外,我现在明白为什么要发短信了,发短信是因为 JSON 回复中有 HTML。