如何访问我的请求负载中的描述字段?
请求有效载荷:
data = { "other_details" :{
"my_story":true,
"preferences":false,
"profile_photo":false,
},
"experience_detail":[
{
"description":"Location: Indan\nCurrent job
responsibilities:\n\n• To manage, interpret,
and integrate inspection and function test data associated
with pressure relief
devices\n• Collection and Managing the database of
inspection/test records\n",
"employer_name":"Wood Group",
"end_date": "2020-04-28",
"id": "30dbe99d0c55435ea3d5119ece0ac873",
"is_current_employer": true,
"job_title": "Integrity Engineer",
"start_date": "2013-11-25"
},
{
"description":"Location: Indian\nCurrent job
responsibilities:\n\n• To manage, interpret,
and integrate inspection and function test data
associated with pressure relief devices\n•
Collection and Managing the database of
inspection/test records\n",
"employer_name":"QUESS CORP.",
"end_date": "2020-04-28",
"id": "30dbe99d0c55435ea3d5119ece0ac873",
"is_current_employer": true,
"job_title": "Integrity Engineer",
"start_date": "2013-11-25"
}
]
}
我尝试了几种方法,但没有奏效。
尝试1:
def index():
data = json.loads(request.data)
clean_description = (data['other_details']
['experience_detail']['description'])
输出:
clean_description = (data['other_details']['experience_detail']['description'])
**TypeError**: list indices must be integers or slices, not str
尝试2:
def index():
data = json.loads(request.data)
clean_description = (data['other_details']['experience_detail'])
输出:
[
{
"description":"Location: Australia\nCurrent job responsibilities:\n\n• To manage, interpret, and integrate inspection and function test data associated with pressure relief devices\n• Collection and Managing the database of inspection/test records\n• Pressure Relief Device (PRD) Inspection Report review/approval and recommendation\n• Compliance check on inspection reports in accordance with the scope and approve and/or send for re-review\n• Database management using Meridium, SAP and other Document Control Databases",
"employer_name":"Wood Group",
"end_date":"2020-04-28",
"id":"30dbe99d0c55435ea3d5119ece0ac873",
"is_current_employer":true,
"job_title":"Integrity Engineer",
"start_date":"2013-11-25"
},
{
"description":"Location: Australia\n\nResponsibilities:\n• Experience in pressure relief device sizing and selection\n• Exposure to Upstream Facilities Engineering activities\n• Experience with SharePoint for document management\n• Experience with Meridium",
"employer_name":"Jacobs Engineering",
"end_date":"2013-10-25",
"id":"7d8afe3cadaa4aee842bb4d8b000f5c7",
"is_current_employer":false,
"job_title":"Integrity Engineer",
"start_date":"2011-11-25"
}
]
它显示所有字段,但我只需要描述字段。
有效载荷的图像:
