问 题
{
"errno": "0",
"data": {
"hi_info": {
"login_ip": "127.0.0.1",
"license": {
"id": "123456",
"name": "hello",
"sex": "",
"status": "1"
},
"hello_info": {
"model": "3",
"license": {
"id": "123456",
"license_no": ""
},
"upgrade": 1
}
}
}
}
如何读取自己想要的数据
比如
hi_info中的login_ip
license中的name
license中的id
以及
data里面所有的数据
解决方案
ex.json:
{
"error": "0",
"data": {
"hi_info": {
"login_ip": "127.0.0.1",
"license": {
"id": "123456",
"name": "hello",
"sex": "",
"status": "1"
},
"hello_info": {
"model": "3",
"license": {
"id": "123456",
"license_no": ""
},
"upgrade": 1
}
}
}
}
代碼:
import json
with open('ex.json' , 'r') as reader:
jf = json.loads(reader.read())
print(jf['data']['hi_info']['login_ip'])
扫一扫关注IT屋
微信公众号搜索 “ IT屋 ” ,选择关注与百万开发者在一起