我以下列格式从API获取json数据:
{"total":254,
"countries":[
{
"name":"Zimbabwe",
"code3":"ZWE",
"code":"ZW"
},
{
"name":"Zambia",
"code3":"ZMB",
"code":"ZM"
},
{
"name":"Yemen",
"code3":"YEM",
"code":"YE"
},
{
"name":"XO",
"code3":"XO ",
"code":"XO"
}
}
这是我访问API数据的PHP脚本:
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'api-key: 1234',
'Content-Type: application/json',
'Accept: application/json'
));
curl_setopt ($curl, CURLOPT_URL, 'https://api.com/api/v3/countries');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec ($curl);
if ($xml === false) {
die('Error fetching data: ' . curl_error($curl));
}
curl_close ($curl);
echo htmlspecialchars("$xml", ENT_QUOTES);
?>
如何以表格格式或引导程序格式调用结果?