onLoad() {
uni.request({
url: 'http://wthrcdn.etouch.cn/weather_mini?city=沈阳',
method: 'GET',
success: res => {
console.log("今天的天气",res.data.data.forecast[0].type);
console.log("今天最高温度",res.data.data.forecast[0].high);
console.log("今天最低温度",res.data.data.forecast[0].low);
console.log("目前气温",res.data.data.wendu);
console.log("明天的天气",res.data.data.forecast[1].type);
console.log("明天最高温度",res.data.data.forecast[1].high);
console.log("明天最低温度",res.data.data.forecast[1].low);
},
fail: () => {
this.openmsg("警告","天气接口获取失败")
},
complete: () => {}
});
}
接收到请求内容:
{
"data": {
"data": {
"city": "沈阳",
"forecast": {
"0": {
"date": "8日星期二",
"fengli": "<![CDATA[2级]]>",
"fengxiang": "南风",
"high": "高温 30℃",
"low": "低温 19℃",
"type": "晴"
},
"1": {
"date": "9日星期三",
"fengli": "<![CDATA[3级]]>",
"fengxiang": "南风",
"high": "高温 29℃",
"low": "低温 19℃",
"type": "多云"
},
"2": {
"date": "10日星期四",
"fengli": "<![CDATA[2级]]>",
"fengxiang": "南风",
"high": "高温 23℃",
"low": "低温 18℃",
"type": "雷阵雨"
},
"3": {
"date": "11日星期五",
"fengli": "<![CDATA[2级]]>",
"fengxiang": "东风",
"high": "高温 27℃",
"low": "低温 17℃",
"type": "多云"
},
"4": {
"date": "12日星期六",
"fengli": "<![CDATA[2级]]>",
"fengxiang": "东风",
"high": "高温 30℃",
"low": "低温 18℃",
"type": "多云"
},
"length": 5
},
"ganmao": "感冒易发期,外出请适当调整衣物,注意补充水分。",
"wendu": "29",
"yesterday": {
"date": "7日星期一",
"fl": "<![CDATA[2级]]>",
"fx": "南风",
"high": "高温 29℃",
"low": "低温 14℃",
"type": "多云"
}
},
"desc": "OK",
"status": 1000
},
"errMsg": "request:ok",
"header": {
"access-control-allow-headers": "*",
"access-control-allow-methods": "*",
"access-control-allow-origin": "*",
"age": "115",
"cache-control": "must-revalidate, max-age=300",
"connection": "keep-alive",
"content-encoding": "gzip",
"content-length": "412",
"date": "Tue, 08 Jun 2021 07:12:28 GMT",
"server": "Tengine/2.3.2",
"x-via-ucdn": "HIT by 218.60.55.7, MISS by 180.97.190.59"
},
"statusCode": 200
}