到目前为止,我有这个 PHP cURL 代码:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://play.dhis2.org/release1/api/25/analytics.json?dimension=dx%3AYtbsuPPo010%3Bl6byfWFUGaP%3Bs46m5MS0hxu&dimension=pe%3ALAST_12_MONTHS&filter=ou%3AImspTQPwCqd&displayProperty=NAME&skipMeta=true",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: Basic YWRtaW46ZGlzdHJpY3Q=",
"cache-control: no-cache",
"postman-token: c7fc6164-194a-24ea-ccea-9f6bdbcd66f5"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
到目前为止,我已经尝试过(不成功):
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$data = json_decode($response, true);
$immunization = $data["rows"];
foreach ($immunizations as $immunization) {
echo '<tr>';
echo '<td>' . $immunization['name'] . '</td>';
echo '<td>' . $immunization['date'] . '</td>';
echo '<td>' . $immunization['type'] . '</td>';
echo '</tr>';
}
}
有人帮我遍历 JSON 并将数据按行放在我的表上。
在邮递员上,使用基本身份验证,用户名:admin,密码:区提前谢谢!