Python解析JSON文件,它是一个带有嵌入式字典的列表 我可以从中得到值,但只能得到字典中最后一条记录的值
代码附在我试过的东西上
import json
access_json = open('shortdocuments.json', 'r')
read_content = json.load(access_json)
# Make list a dictionary
for question_access in read_content:
print(type(question_access))
replies_access = question_access['Attachment']
for i in replies_access:
print(i,"|",replies_access[i])
想把所有的唱片都这样放出来
CreateDate | 2019-10-16T09:13:33
Description |
CreateUserID | 1
Path | 201910\10489_AParker_T0231056_13.pdf
Name | 10489_AParker_T0231056_13
FileID | 765
IsDepotUsed | True
Extension | .pdf
UpdateDate | 2019-10-16T09:13:33
UpdateUserID | 1
我的JSON文件
[
{
"UserDefinedValueID": 872,
"UserDefinedFieldID": 56,
"ParentID": 355,
"Name": "PDM_Application",
"Value": "763",
"UpdateDate": "2019-10-27T14:29:18",
"FieldType": "File",
"Attachment": {
"FileID": 763,
"Name": "03981-00117",
"Description": "",
"IsDepotUsed": true,
"Path": "201910\\03981-00117.pdf",
"Extension": ".pdf",
"CreateDate": "2019-10-16T09:13:32",
"UpdateDate": "2019-10-27T14:29:18",
"CreateUserID": 1,
"UpdateUserID": 1
},
"UpdateUserID": 1,
"CreateUserID": 1 },
{
"UserDefinedValueID": 873,
"UserDefinedFieldID": 57,
"ParentID": 355,
"Name": "PDM_LeaseDoc",
"Value": "764",
"UpdateDate": "2019-10-16T09:13:33",
"FieldType": "File",
"Attachment": {
"FileID": 764,
"Name": "09658-00060_t0007192_Application",
"Description": "",
"IsDepotUsed": true,
"Path": "201910\\09658-00060_t0007192_Application.pdf",
"Extension": ".pdf",
"CreateDate": "2019-10-16T09:13:33",
"UpdateDate": "2019-10-16T09:13:33",
"CreateUserID": 1,
"UpdateUserID": 1
},
"UpdateUserID": 1,
"CreateUserID": 1 },
{
"UserDefinedValueID": 875,
"UserDefinedFieldID": 59,
"ParentID": 355,
"Name": "PDM_FAS/SODA",
"Value": "765",
"UpdateDate": "2019-10-16T09:13:33",
"FieldType": "File",
"Attachment": {
"FileID": 765,
"Name": "10489_AParker_T0231056_13",
"Description": "",
"IsDepotUsed": true,
"Path": "201910\\10489_AParker_T0231056_13.pdf",
"Extension": ".pdf",
"CreateDate": "2019-10-16T09:13:33",
"UpdateDate": "2019-10-16T09:13:33",
"CreateUserID": 1,
"UpdateUserID": 1
},
"UpdateUserID": 1,
"CreateUserID": 1
}
]
在for循环之后,您使用的变量仍在作用域中。你知道吗
您需要在循环下缩进代码,以便对每个项执行操作
编辑:如果你想要一个CSV类型的格式,你可以试试这个
输出
或者用熊猫
相关问题 更多 >
编程相关推荐