您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

xml - php调用新浪天气API遇到的一个问题

2024/10/23 11:17:56发布29次查看
调用新浪天气的api(xml格式返回),可以得到xml字符串,可是装载到对象中后却输出不出来,是怎么回事?
getweather(); class weather { private $apiurl = 'http://php.weather.sina.com.cn/xml.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 = 'http://php.weather.sina.com.cn/xml.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;
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product