为了账号安全,请及时绑定邮箱和手机立即绑定

为什么装载到对象中后却输出不出来,是怎么回事?

为什么装载到对象中后却输出不出来,是怎么回事?

牧羊人nacy 2023-04-25 19:15:16
调用新浪天气的API(xml格式返回),可以得到xml字符串,可是装载到对象中后却输出不出来,是怎么回事?    <?php        /**      *       */       $w = new Weather();       echo $w->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;                          }       }       ?>
查看完整描述

1 回答

?
湖上湖

TA贡献2003条经验 获得超2个赞

$weather = $result->pollution;//xml中的一个子节点
修改为:
$weather = $result->Weather->pollution;


查看完整回答
反对 回复 2023-04-28
  • 1 回答
  • 0 关注
  • 113 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信