我试图从大量文件中提取一些数据并将它们转换为特定的(JSON)格式,以便使用 Django Fixtures 导入数据库
我已经能够做到这一点:
'{ {\n "pk":2,\n "model": trial.conditions,\n "fields": {\n "trial_id": NCT00109798,\n "keyword": Brain and Central Nervous System Tumors,\ n }{\n "pk":3,\n "model": trial.conditions,\n "fields": {\n "trial_id": NCT00109798,\n "keyword": 淋巴瘤,\n }{\n "pk": 2,\n "model": trial.criteria,\n "fields": {\n "trial_id": NCT00109798,\n "gender": Both,\n "minimum_age": 18 年,\n "maximum_age": N/A,\n "healthy_volunteers": 否,\n "textblock": ,\n }\n\t\t"pk":2,\n\t\t"model": trial.keyword,\n\t\t"fields": {\n\t\t"trial_id": NCT00109798,\n\t\t"keyword ": 原发性中枢神经系统非霍奇金淋巴瘤,\n\t\t}\n\t\t
......很多行之后......
研究治疗完成后,患者每 3 个月随访 1 年,每\n 4 个月随访 1 年,然后每 6 个月随访 3 年。\n\n 预计累积:总共 6-25 名患者将为本研究累积。\n ,\n "overall_status": 招募中,\n "phase": 第 2 阶段,\n "enrollment": 25,\n "study_type": 介入,\n "condition": 2,3 ,\n "criteria": 1,\n "overall_contact": testdata,\n "location": 4,\n "lastchanged_date": March 31, 2010,\n "firstreceived_date": May 3, 2005,\n "关键字": 2,3,\n "condition_mesh": ,\n }\n \n {\n "pk": testdata,\n "model": trial.contact,\n "fields": {\n "trial_id": NCT00109798,\n "last_name": Pamela Z. New, MD,\n "phone": ,\n "email": ,\n }}'
输出实际上需要如下所示:
{
"pk": trial_id,
"model": trials.trial,
"fields": {
"trial_id": trial_id,
"brief_title": brief_title,
"official_title": official_title,
"brief_summary": brief_summary,
"detailed_Description": detailed_description,
"overall_status": overall_status,
"phase": phase,
"enrollment": enrollment,
"study_type": study_type,
"condition": _______________,
"elligibility": elligibility,
"criteria": ______________,
"overall_contact": _______________,
"location": ___________,
"lastchanged_date": lastchanged_date,
"firstreceived_date": firstreceived_date,
"keyword": __________,
"condition_mesh": condition_mesh,
}
"pk": null,
"model": trials.locations,
"fields": {
"trials_id": trials_id,
"facility": facility,
"city": city,
"state": state,
"zip": zip,
"country": country,
}
任何建议将不胜感激。