1.返回的数据格式:
返回的数据结构为python字典嵌套list。
2.测试源码:
# -*- coding: utf-8 -*-
import http.client, urllib,json
conn = http.client.HTTPSConnection('') #接口域名
params = urllib.parse.urlencode({'key':'改为你申请的KEY','city':'上海市'})
headers = {'Content-type':'application/x-www-form-urlencoded'}
conn.request('POST','/tianqi/index',params,headers)
res = conn.getresponse()
data = res.read()#读字符串
data = data.decode('utf-8')# 格式转换
data2 = json.loads(data) # 将 JSON 对象转换为 Python 字典
print("地区:",data2['newslist'][0]['area'])
print("日期:",data2['newslist'][0]['date'])
print("星期:",data2['newslist'][0]['week'])
print("天气:",data2['newslist'][0]['weather'])
3.打印结果: