php 新浪天气api,xml

php 新浪天气api,xml

调用新浪天气的API(xml格式返回),可以得到xml字符串,可是装载到对象中后却输出不出来,是怎么回事?getWeather();

class Weather

{

private $apiUrl = '.php?city=%B1%B1%BE%A9&password=DJOYnieT8234jlsK&day=0';

public function getWeather()

{

$xml = file_get_contents($this->apiUrl);

$result = simplexml_load_string($xml);

$weather = $result->pollution;//xml中的一个子节点

return $weather;

}

}

?>

回复内容:

调用新浪天气的API(xml格式返回),可以得到xml字符串,可是装载到对象中后却输出不出来,是怎么回事?getWeather();

class Weather

{

private $apiUrl = '.php?city=%B1%B1%BE%A9&password=DJOYnieT8234jlsK&day=0';

public function getWeather()

{

$xml = file_get_contents($this->apiUrl);

$result = simplexml_load_string($xml);

$weather = $result->pollution;//xml中的一个子节点

return $weather;

}

}

?>

$weather = $result->pollution;//xml中的一个子节点

修改为:

$weather = $result->Weather->pollution; 本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉 本文系统来源:php中文网

发布者:admin,转转请注明出处:http://www.yc00.com/web/1731140528a3621311.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信