亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么裝載到對象中后卻輸出不出來,是怎么回事?

為什么裝載到對象中后卻輸出不出來,是怎么回事?

牧羊人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 關注
  • 214 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號