python解析json数据
python解析json数据
demo
data = {
"name": "John",
"age": 30,
"hobbies": ["reading", "running", "swimming"],
"scores": [85, 90, 95]
}
for key, value in data.items():
if isinstance(value, list):
# 当值为列表类型时
print(f"{key} is a list:")
for item in value:
print(item)
else:
# 当值不是列表类型时
print(f"{key}: {value}")
读取json文件
# 从JSON文件中读取数据
with open('example_json.json', 'r', encoding='utf-8') as file:
data = json.load(file)
res_list = []
res = data["xxx"]
for key, value in res.items():
print(key)
好看请赞,养成习惯:) 本文来自博客园,作者:靠谱杨, 转载请注明原文链接:https://www.cnblogs.com/rainbow-1/p/17527745.html
欢迎来我的51CTO博客主页踩一踩 我的51CTO博客
文章中的公众号名称可能有误,请统一搜索:靠谱杨的秘密基地