{
"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'])
我回答過的問題: Python-QA
读取列表?还是读取json?
JSON格式的文件用json模块,会转换成dict和list,好好看书吧。
这个并不是列表啊,这个叫哈希表额。
hash_table['data']['hi_info']['login_ip']
hash_table['data']['hi_info']['hello_info']['license']['id']
如果要读入json文件用json
模块