【发布时间】:2020-05-05 19:16:49
【问题描述】:
大家好,
我有以下代码:
import json
import pprint
with open('77.json', 'r') as file:
data = json.load(file)
somedata = data.get('"name":')
printer = pprint.PrettyPrinter()
print('somedata')
json文件中的代码是这样的:
[ { "id": "0f78f3f6-0efe-49bc-9283-7daf23c142f0", "name": "利用网络设备进行 DHCP", “蛞蝓”:“利用-网络设备-for-dhcp”, “duration_in_seconds”:473, “状态”:“准备就绪”, “元数据”:{ “公司”:“xxx” }, “instructor_id”:“e72b1785-711e-42b4-b795-f3523fe3a7d8”, “创建”:“2020-04-15T01:18:51Z”, “修改”:“2020-04-30T18:34:46.111771Z”, "s3_video_url": "http//:blabla4", “excel_id”:“e1ZTXDBr” }, {
问题是我的代码出错了:
python test.py
Traceback (most recent call last):
File "test.py", line 7, in <module>
somedata = data.get('"name":')
AttributeError: 'list' object has no attribute 'get'
我想从“名称”中提取所有内容:
我想从以“名称”开头的每一行中提取所有信息:
应该是这样的:
Introducing Northbound & Southbound APIs
SDN’s Relationship To Management, Control & Data Planes
以此类推。
对不起,我忘了说我是初学者。
提前致谢
【问题讨论】:
-
异常
AttributeError: 'list' object has no attribute 'get'表示数据是list,而list没有get属性。 -
数据[“名称”]呢?