【问题标题】:what is the way to write code in python to print only sai details?在 python 中编写代码以仅打印 sai 详细信息的方法是什么?
【发布时间】:2021-12-31 07:46:34
【问题描述】:

在文件中有一个 JSON 数据,我正在尝试仅从“sai”检索数据
https://drive.google.com/file/d/1r7tnZjFSvggfkI890vgmRmiv16_kAbY4/view?usp=sharing

import json
with open("student_detailsdb.json","r") as fp:
    data = json.load(fp)
for i in data:
    print(i["sai"])

【问题讨论】:

标签: python-3.x


【解决方案1】:

请检查迭代 (i) 中存在的“sai”键,然后它将仅打印 sai 详细信息

import json
with open("student_detailsdb.json","r") as fp:
    data = json.load(fp)
for i in data:
    if "sai" in i:
       print(i["sai"])

【讨论】:

  • @SaiKiran 欢迎您!如果对您有帮助,请点赞并接受答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-10
  • 2016-03-25
  • 1970-01-01
  • 1970-01-01
  • 2017-02-03
相关资源
最近更新 更多