首页 > 编程语言 >python 读取json文件

python 读取json文件

时间:2022-08-26 15:13:31浏览次数:102  
标签:Python 读取 jess python courses json fcc name

一个jason文件实例————fcc.json
{
"organization": "freeCodeCamp",
"website": "https://www.freecodecamp.org/",
"formed": 2014,
"founder": "Quincy Larson",
"certifications": [
{
"name": "Responsive Web Design",
"courses": [
"HTML",
"CSS"
]
},
{
"name": "JavaScript Algorithms and Data Structures",
"courses": [
"JavaScript"
]
},
{
"name": "Front End Development Libraries",
"courses": [
"Bootstrap",
"jQuery",
"Sass",
"React",
"Redux"
]
},
{
"name": "Data Visualization",
"courses": [
"D3"
]
},
{
"name": "Relational Database Course",
"courses": [
"Linux",
"SQL",
"PostgreSQL",
"Bash Scripting",
"Git and GitHub",
"Nano"
]
},
{
"name": "Back End Development and APIs",
"courses": [
"MongoDB",
"Express",
"Node",
"NPM"
]
},
{
"name": "Quality Assurance",
"courses": [
"Testing with Chai",
"Express",
"Node"
]
},
{
"name": "Scientific Computing with Python",
"courses": [
"Python"
]
},
{
"name": "Data Analysis with Python",
"courses": [
"Numpy",
"Pandas",
"Matplotlib",
"Seaborn"
]
},
{
"name": "Information Security",
"courses": [
"HelmetJS"
]
},
{
"name": "Machine Learning with Python",
"courses": [
"Machine Learning",
"TensorFlow"
]
}
]
}

点击查看代码
#%%
import json

import jsonpath

jess = '{"name": "Jessica Wilkins", "hobbies": ["music", "watching TV", "hanging out with friends"]}'
jess_dict = json.loads(jess)

# Printed output: {"name": "Jessica Wilkins", "hobbies": ["music", "watching TV", "hanging out with friends"]}
print(jess_dict)


with open('fcc.json', 'r') as fcc_file:
    fcc_data = json.load(fcc_file)
    
  
print(fcc_data['certifications'][0]['name'])
    
    
#%%  
   #读取json文件并只收集其中name的值
   obj = json.load(open('fcc.json', 'r', encoding='utf-8')) 
   names = jsonpath.jsonpath(obj, '$..name')  # 文件对象   jsonpath语法 
   

标签:Python,读取,jess,python,courses,json,fcc,name
From: https://www.cnblogs.com/torrentgz/p/16627594.html

相关文章

  • springboot:@RequestBody 注解只能处理json格式的请求字符串吗?
    原来@RequestBody注解常用来处理content-type是application/json编码的内容,而不能用来处理application/x-www-form-urlcoded编码的内容。参考:https://blog.csdn.n......
  • Linux安装python并配置环境变量
    1.获取python3源码我们访问这个网址,就可以看到全部的python下载方式:【https://www.python.org/downloads/】   本人下载的是3.10.6版本   2.安装Python这......
  • python学习课后练习
    此次爬虫学习的资源是B站所找,具体如下:Python课程天花板,Python入门+Python爬虫+Python数据分析5天项目实操/Python基础,该课程留了课后练习,我把自己的代码和想法单独整成一......
  • python基础——模块 包
    模块包Python模块(Module),是一个Python文件,以.py结尾,包含了Python对象定义和Python语句。模块能定义函数,类和变量,模块里也能包含可执行的代码。模块和包以及库,......
  • cinrad 读取雷达 bz2 文件数据
    安装pipinstallcinrad-ihttps:mirrors.aliyun.com/pypi/simple读取文件importcinradfilename=r"Z_RADA_C_BABJ_20220720060001_P_DOR_Z9518_BASE_2022082......
  • Linux-Centos 用crontab定时运行python脚本详细步骤
    服务器运行定时任务操作步骤:1.编辑crontab配置命令:  crontab-e可进行编辑定时任务  crontab-l查看定时任务列表 crontab-r删除定时任务 servicecro......
  • Python中常见的异常类型
    #Python常见的异常类型'''第一种数学数据异常'''#print(1/0)#ZeroDivisionError'''第二种,序列中没有这个索引'''lst=[11,22,33]#print(lst[3])#IndexError'''第......
  • 关于java远程调用接口,处理返回值为json的记录
    当远程调用接口时,需要处理返回的值,有时候需要转为json例如:HashMap<Object,Object>mapTemp=newHashMap<>();mapTemp.put("classId",classId);mapTemp.put("com......
  • Python基础——迭代器 生成器
    迭代器iterator迭代简单理解就是重复,但是每次重复产生的结果还要作为下次重复的初始值。可迭代对象:含有——iter——方法的对象。可以用for...in..遍历的都是可迭代对......
  • Python爬虫:抖音个人主页视频抓取
    目标:抓取抖音某博主发布的全部视频用到的模块selenium+requests整体思路:1、先用selenium自动化让数据加载出来到视频获取详情页的链接     2、然后在......