现在,我必须处理一个json不好的数据库。 因此,当我试图在python中每1行恢复所有第1行时,这是不可能的,因为数据库总是有问题
我不知道如何恢复它来处理这个数据库
我试过这个:
my_json = {
"name": "Khau0304lid Muhu0323ammad u02bbAliu0304 al-Hu0323au0304jj",
"personal_name": "Khau0304lid Muhu0323ammad u02bbAliu0304 al-Hu0323au0304jj",
"last_modified": {
"type": "/type/datetime",
"value": "2008-08-20T17:57:09.66187"
},
"key": "/authors/OL1000057A",
"type": {
"key": "/type/author"
},
"revision": 2
}
name = my_json.get('name', "")
print(name)
但是当我有一个以上的名字时,它就不起作用了
谢谢你的关注
下面是一个使用字符串的示例
结果将是
['Halo', 'haha', 'zzzz']
如果你有一个json文件, 然后
更多关于object_pairs_hook
好的,下面是一个示例,用于分割许多json字符串
JsonList
中的每个元素都是一个完整的json字符串。您可以将JsonList
中的每个元素保存到json文件中,然后运行我首先发布的内容保存它:
它将生成一些json文件。 你可以把它和我的第一篇文章联系起来
我想你可能误解了我。 您的
openlibrary5.json
在一个文件中有许多json因此,如果您直接将此文件作为json加载。 像这样,
将出现错误
所以我建议你可以先把它们切成薄片
然后按照我的帖子将它们分割成许多(另存为)json文件。 切片后,其中一个切片的json文件是完整的json。 因此,您可以使用
json.load()
正常加载它们如果您真的想将它们聚集在一起,在对它们进行切片之后,您可以打开每个切片的json文件,并将它们放在一个
List
(使用List.append)明白了吗
相关问题 更多 >
编程相关推荐