Python 在json中从数据库中的属性恢复所有行

Python 在json中从数据库中的属性恢复所有行,python,json,database,Python,Json,Database,为了简化我的问题,我在json中有一个基数,我恢复了所有json行,将信息放入基数中。 这看起来很容易,但问题是我的json编写不正确 因此,我编写了一段代码来恢复我所有的json行,但它不能在所有行上运行,比如“传记” 我给你看 {"name": "Nazamiu0304 Rau0304majiu0304", "personal_name": "Nazamiu0304 Rau0304majiu0304", "last_modified": {"type": "/type/datetime",

为了简化我的问题,我在json中有一个基数,我恢复了所有json行,将信息放入基数中。 这看起来很容易,但问题是我的json编写不正确

因此,我编写了一段代码来恢复我所有的json行,但它不能在所有行上运行,比如“传记”

我给你看

{"name": "Nazamiu0304 Rau0304majiu0304", "personal_name": "Nazamiu0304 Rau0304majiu0304", "last_modified": {"type": "/type/datetime", "value": "2008-08-20T18:00:41.270799"}, "key": "/authors/OL1001461A", "type": {"key": "/type/author"}, "revision": 2}
{"name": "Nazamiu0304 Rau0304majiu0304", "personal_name": "Nazamiu0304 Rau0304majiu0304", "last_modified": {"type": "/type/datetime", "value": "2008-08-20T18:00:41.270799"}, "key": "/authors/OL1001461A", "type": {"key": "/type/author"}, "revision": 2}
你看,你有名字,个人名字

有时候你有其他的信息

{"bio": {"type": "/type/text", "value": "> "Eversley, William Pinder, B.C.L. Queen's Coll., Oxon, M.A., a member of the South-eastern circuit, reporter for Law Times in Queen's Bench division, a student of the Inner Temple 14 April, 1874 (then aged 23), called to the bar 25 April, 1877 (eldest son of William Eversley, Esq., of London); born u2060, 1851. rn> rn> 7, King's Bench Walk, Temple, E.C." rn> ...[in Foster's _Men at the Bar_][1]rnrnrn  rnrn[1]: https://en.wikisource.org/wiki/Men-at-the-Bar/Eversley,_William_Pinder "Men at the Bar""}, "name": "William Pinder Eversley", "created": {"type": "/type/datetime", "value": "2008-04-01T03:28:50.625462"}, "death_date": "1918", "photos": [6897255, 6897254], "last_modified": {"type": "/type/datetime", "value": "2018-07-31T15:39:07.982159"}, "latest_revision": 6, "key": "/authors/OL1003081A", "birth_date": "1851", "personal_name": "William Pinder Eversley", "type": {"key": "/type/author"}, "revision": 6}


{"name": "Valerie Meyer", "personal_name": "Valerie Meyer", "last_modified": {"type": "/type/datetime", "value": "2008-08-20T18:22:33.63997"}, "key": "/authors/OL1004062A", "type": {"key": "/type/author"}, "revision": 2}
你可以看到我对“bio”这个元素有很多问题:因为他写得一点也不正确,配额的解释也不正确,“rn>7,东卡罗来纳州坦普尔国王长凳步道。”rn>…[在福斯特的《酒吧里的男人》][1]rnrnrn[1]:https://en.wikisource.org/wiki/Men-at-the-Bar/Eversley“酒吧里的男人” }, “姓名”:“威廉·平德·埃弗斯利”, “已创建”:{ “类型”:“/type/datetime”, “值”:“2008-04-01T03:28:50.625462” }, “死亡日期”:“1918年”, “照片”:[ 6897255, 6897254 ], “上次修改”:{ “类型”:“/type/datetime”, “价值”:“2018-07-31T15:39:07.982159” }, “最新修订”:6, “密钥”:“/authors/OL1003081A”, “出生日期”:“1851年”, “个人姓名”:“威廉·平德·埃弗斯利”, “类型”:{ “键”:“/类型/作者” }, “修订”:6 }""" result=bio\u regex.sub(规范化\u bio、凌乱\u json) obj=json.loads(结果) 结果如下:


{'bio': {'type': '/type/text',
         'value': '> "Eversley, William Pinder, B.C.L. Queen\'s Coll., Oxon, M.A., a member of the '
                  "South-eastern circuit, reporter for Law Times in Queen's Bench division, a student of "
                  'the Inner Temple 14 April, 1874 (then aged 23), called to the bar 25 April, 1877 (eldest '
                  "son of William Eversley, Esq., of London); born u2060, 1851. rn> rn> 7, King's Bench "
                  'Walk, Temple, E.C." rn> ...[in Foster\'s Men at the Bar][1]rnrnrn rnrn[1]: '
                  'https://en.wikisource.org/wiki/Men-at-the-Bar/Eversley,_William_Pinder "Men at the Bar"'},
 'birth_date': '1851',
 'created': {'type': '/type/datetime', 'value': '2008-04-01T03:28:50.625462'},
 'death_date': '1918',
 'key': '/authors/OL1003081A',
 'last_modified': {'type': '/type/datetime', 'value': '2018-07-31T15:39:07.982159'},
 'latest_revision': 6,
 'name': 'William Pinder Eversley',
 'personal_name': 'William Pinder Eversley',
 'photos': [6897255, 6897254],
 'revision': 6,
 'type': {'key': '/type/author'}}

这里的问题是,如果我把我的整行代码放在我的代码中,这个脚本是好的,但是我想用好的结构恢复我的1000000行bio,我不能做到每1行恢复1行,我尝试了很多循环来恢复每1行1行,但它总是让我出错,我需要知道如何通过循环来恢复它。 我需要升级我的代码,从line bio中获取数据库的所有行,而不仅仅是每1行1行


提前谢谢,谢谢听我说

例如,我想说:我有一个文件,openlibraryjson.json:

以下几行:


{“姓名”:“伊斯梅尔·易卜拉欣博士”,“头衔”:“博士”,“个人姓名”:“伊斯梅尔·易卜拉欣”,“上次修改”:{“类型”:“/类型/日期时间”,“值”:“2008-04-01T03:28:50.625462”},“键”:“/作者/OL100304A”,“类型”:{“键”:“/类型/作者”},“修订版”:1}
{“bio”:{“type”:“/type/text”,“value”:“>“埃弗斯利,威廉·平德,B.C.L.皇后学院,奥克森,M.A.,东南巡回赛成员,女王法官区《法律时报》记者,1874年4月14日内殿的一名学生(当时23岁),1877年4月25日获得律师资格(威廉·埃弗斯利的长子,伦敦Esq.)出生于U206201851年。出生于英格兰东卡罗来纳州坦普尔国王长凳步道7号。死亡日期:1918年,照片:[6897255,6897254],“上次修改:{”类型:“/日期:“/时间”,“价值”:“2008-04-01T03:28:50.625462”;“死亡日期”:“1918年”,“照片:[6897255,6897254],“上次修改:{”类型:“/日期”,“value”:“2018-07-31T15:39:07.982159”},“最新修订版”:6,“key”:“/authors/OL1003081A”,“出生日期”:“1851”,“个人姓名”:“William Pinder Eversley”,“type”:“{“key”:“/type/author”},“修订版”:6}
{“name”:“Valerie Meyer”,“personal_name”:“Valerie Meyer”,“last_modified”:{“type”:“/type/datetime”,“value”:“2008-08-20T18:22:33.63997”},“key”:“/authors/OL1004062A”,“type”:{“key”:“/type/author”},“revision”:2}
{“bio”:{“type”:“/type/text”,“value”:“[Deutsch]Deutscher Orientilist and Deutscher Orientilist and Theology.rn[英语]德国东方学家和圣经学者”},“姓名”:“August Dillmann”,“链接”:[{“url”:“/type/link”},“标题”:“Wikipedia(Deutsch)”},{“url”:“type”:“{“key”:“/type/link”},“标题”:“Wikipedia(英语)”,“个人姓名”:奥古斯特·迪尔曼,“死亡日期”:“1894年7月4日”。“候补姓名”:[“克里斯蒂安·弗里德里希·奥古斯特·迪尔曼”,“Ch.F.A.迪尔曼”,“弗里德里希·奥古斯特·迪尔曼”,“F.A.迪尔曼”,“奥古斯都·迪尔曼”,“奥古斯特·迪尔曼”,“A.迪尔曼”],“创建的”:{“类型”:“/类型/日期时间”,“值”:“2008-04-01T03:28:50.625462”},“照片”:[6676274],“最后修改的”:{”键入“/type/datetime”、“value”:“2017-03-31T12:45:57.925108”},“最新修订版”:8,“key”:“/authors/OL1179559A”、“出生日期”:“1823年4月25日”、“修订版”:8,“type”:“{”key:“/type/author”},“远程ID”:{”viaf:“45046685”、“wikidata:“Q75216”}
{“last_modified”:{“type”:“/type/datetime”,“value”:“2008-04-01T03:28:50.625462”},“type”:{“key”:“/type/author”},“name”:“Physikertagung(1966年,德国慕尼黑)”,“key”:“/authors/OL1179696A”,“revision”:1}

我只想把行bio和处理他们把他们功能,因为它我试图打开我的文件,我处理名称,个人_名称…与一个循环,它的工作,但不为bio,因为它写得不正确,所以我跳过了我的脚本的bio的时刻,但现在我不想跳过bio和工作与bio的方式相同,为名称,pers你的名字

喜欢它:


以open('openlibrary(3.json')作为文件:
对于范围(101)内的i:
line=file.readline()
如果行中有“bio”:
行。替换(“\”,“”)
持续
content_json=json.loads(第行)
如果行中没有“个人姓名”:
#打印('NULL')
ligne.append(“NULL”)
持续
尝试:
#打印(内容\u json['name'])
append(content_json['personal_name'])
除索引器外:
打印('NULL')
如果行中没有“个人姓名”:
#打印('NULL')
个人名称附加(“空”)
持续
尝试:
#打印(内容\u json['name'])
personal_nom.append(content_json['personal_name'])
除索引器外:
打印('NULL')

我只是在这里放了一些代码来展示我对名字,个人名字做了些什么


再次感谢您倾听我并回答我!!!!

另一种使其成为有效的
json
:ty对于您的答案,我检查了它,它工作正常,但是