我已将新数据添加到我的API。我想将它作为纯文本返回API数据返回HTML
这是PHP返回的API响应。
{
"apiVersion":"1.0",
"data":{
"location":"London",:
{
"pressure":"1021",
"temperature":"23",
"skytext":"Sky is Clear",
"humidity":"40",
"wind":"18.36 km/h",
"date":"07-10-2015",
"day":"Friday"
}
}
我想返回我的html页面上的压力值,以便我的用户可以看到读数。我有问题显示它。
这是我的PHP api.php
require_once('./includes/config.php');
require_once('./includes/functions.php');
error_reporting(0);
header('Content-Type: text/plain; charset=utf-8;');
$city = $_GET['city'];
if(isset($city)) {
$weather = new Weather($conf['apikey'], $_GET['f']);
$weather_current = $weather->get($city, 0, 0, null, null);
$now = $weather->data(0, $weather_current);
if($now['location'] !== NULL) {
echo '{"apiVersion":"1.0", "data":{ "location":"'.$now['location'].'", "temperature":"'.$now['temperature'].'", "pressure":"'.$now['pressure'].'", "skytext":"'.$now['description'].'", "humidity":"'.$now['humidity'].'", "wind":"'.$now['windspeed'].'", "date":"'.$now['date'].'", "day":"'.$now['day'].'" } }';
} else {
echo '{"apiVersion":"1.0", "data":{ "error":"The \'city\' requested is not available, make sure it\'s a valid city." } }';
}
} else {
echo '{"apiVersion":"1.0", "data":{ "error":"You need to specify the city parameter" } }';
}
'{“apiVersion”:“1.0”,“data”:{“location”:“London”:{ “pressure”:“1021”,“temperature”:“23”,“skytext”是湿度“:”40“,”风“:”18.36公里/小时“,”日期“:”07-10-2015“, ”天“:”星期五“}} – Cyclonecode
我展示了json结果,我仍然试图调试这只需要一点点帮助解决问题 – user3146197
如果你可以提供更多的上下文,它会更容易帮助你。截至目前,我们几乎没有工作。 – AnotherGuy