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

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

使用json_decode在PHP中解析JSON對象

使用json_decode在PHP中解析JSON對象

PHP
郎朗坤 2019-09-02 11:06:11
我試圖通過提供JSON格式數據的Web服務請求天氣。我的PHP請求代碼沒有成功,是:$url="http://www.worldweatheronline.com/feed/weather.ashx?q=schruns,austria&format=json&num_of_days=5&key=8f2d1ea151085304102710";$json = file_get_contents($url);$data = json_decode($json, TRUE);echo $data[0]->weather->weatherIconUrl[0]->value;    這是返回的一些數據。為簡潔起見,部分細節已被截斷,但保留了對象完整性:{ "data":     { "current_condition":         [ { "cloudcover": "31",            ... } ],        "request":         [ { "query": "Schruns, Austria",            "type": "City" } ],      "weather":         [ { "date": "2010-10-27",            "precipMM": "0.0",            "tempMaxC": "3",            "tempMaxF": "38",            "tempMinC": "-13",            "tempMinF": "9",            "weatherCode": "113",            "weatherDesc": [ {"value": "Sunny" } ],            "weatherIconUrl": [ {"value": "http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png" } ],            "winddir16Point": "N",            "winddirDegree": "356",            "winddirection": "N",            "windspeedKmph": "5",            "windspeedMiles": "3" },           { "date": "2010-10-28",            ... },          ... ]        }    }}
查看完整描述

3 回答

?
紅顏莎娜

TA貢獻1842條經驗 獲得超13個贊

如果您使用以下代碼:


$json = file_get_contents($url);

$data = json_decode($json, TRUE);

TRUE返回一個數組而不是一個對象。


查看完整回答
反對 回復 2019-09-02
  • 3 回答
  • 0 關注
  • 550 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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