使用此代码,我将API与我的项目连接起来。
在$sCurloptUrl
中是我的API网址,我从中检索了一些数据并将其放在json格式中。我设法检索除time_from
和time_to
之外的所有内容。我的网址需要如下所示:http://localhost/Something/json.php?json_id=get_measurements&measuringStation_id=551&matter_id=2&data_type=4&time_from=16.5.2018&time_to=18.5.2018
如何获取time_from和time_to?
case 'get_measurements':
$nMeasuringStationID= $_GET['measuringStation_id'];
$nMatterID = $_GET['matter_id'];
$nDataType = $_GET['data_type'];
$sTimeFrom = $_GET['time_from'];
$sTimeTo = $_GET['time_to'];
$sCurloptUrl = 'http://iszz.azo.hr/iskzl/rs/podatak/export/json?measuringStation='.$nMeasuringStationID.'&polutant='.$nMatterID.'&dataType='.$nDataType.'&timeFrom='.$sTimeFrom.'&timeTo='.$sTimeTo.'';
$headers = [
'Content-Type: application/json',
];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPGET => true,
CURLOPT_SAFE_UPLOAD => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_URL => $sCurloptUrl
));
$oResponse = curl_exec($curl);
curl_close($curl);
$oResponse = json_decode($oResponse, true);
//var_dump($oResponse);
foreach ($oResponse as $Measurements)
{
$oMeasurement = new Measurement( $Measurements['Data']['value'], $Measurements['Data']['measuring_unit'], $Measurements['Data']['time']);
array_push($oJson, $Measurements);
}
break;
答案 0 :(得分:0)
你的网址中有time_from但是你使用timeFrom添加它,并且timeTo和time_to相同 所以这将得到你的价值观:
$sTimeFrom = $_GET['timeFrom'];
$sTimeTo = $_GET['timeTo'];