python如何读取列表中的参数

查看:226
本文介绍了python如何读取列表中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

{
  "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

这篇关于python如何读取列表中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆