📅  最后修改于: 2023-12-03 15:08:11.839000             🧑  作者: Mango
欢迎使用天气 Kasur,这是一个专门为卡苏尔地区提供天气信息的程序。
GET /weather/today
返回的 JSON 格式如下所示:
{
"date": "2022-07-23",
"weather": "晴",
"temperature": {
"low": "28℃",
"high": "35℃"
},
"wind": "东南风3-4级"
}
| 参数名 | 类型 | 是否必须 | 描述 | | ---------- | ------ | -------- | -------------------------- | | - | - | - | - |
| 参数名 | 类型 | 描述 |
| ------------ | ------ | ---------------- |
| date
| string | 日期,格式 YYYY-MM-DD |
| weather
| string | 天气情况 |
| temperature.low
| string | 最低温度 |
| temperature.high
| string | 最高温度 |
| wind
| string | 风向风力 |
GET /weather/7days
返回的 JSON 格式如下所示:
[
{
"date": "2022-07-23",
"weather": "晴",
"temperature": {
"low": "28℃",
"high": "35℃"
},
"wind": "东南风3-4级"
},
{
"date": "2022-07-24",
"weather": "多云",
"temperature": {
"low": "27℃",
"high": "34℃"
},
"wind": "东南风3-4级"
},
...
]
| 参数名 | 类型 | 是否必须 | 描述 | | ---------- | ------ | -------- | -------------------------- | | - | - | - | - |
返回一个数组,每个元素的参数说明见上面的“查询当天天气”。
import requests
url = "http://example.com/weather/today"
response = requests.get(url)
json_data = response.json()
weather = json_data['weather']
low_temp = json_data['temperature']['low']
high_temp = json_data['temperature']['high']
print(f"今天天气{weather},最低温度{low_temp},最高温度{high_temp}")
const url = "http://example.com/weather/today";
fetch(url)
.then(response => response.json())
.then(data => {
const weather = data.weather;
const lowTemp = data.temperature.low;
const highTemp = data.temperature.high;
console.log(`今天天气${weather},最低温度${lowTemp},最高温度${highTemp}`);
});
$url = "http://example.com/weather/today";
$jsonData = file_get_contents($url);
$data = json_decode($jsonData, true);
$weather = $data['weather'];
$lowTemp = $data['temperature']['low'];
$highTemp = $data['temperature']['high'];
echo "今天天气{$weather},最低温度{$lowTemp},最高温度{$highTemp}";