Python将Json转换为SQLite?

bbmckpt7  于 2023-01-26  发布在  SQLite
关注(0)|答案(1)|浏览(231)

所以我希望从json转换到sqlite,因为我有一个json文件,其中有500,000个条目,并且追加+转储文件的时间太长。这是我的json文件的样子:

{"number": "1234567890", "used_services": [], "service": "television"},
{"number": "1234567890", "used_services": [], "service": "television"},
{"number": "1234567890", "used_services": [], "service": "television"},
{"number": "123457890", "used_services": [], "service": "television"},
{"number": "1234567890", "used_services": [], "service": "television"},
{"number": "123457890", "used_services": [], "service": "television"},
{"number": "1234567890", "used_services": [], "service": "television"},
{"number": "1234567890", "used_services": [], "service": "television"},
{"number": "1234567890", "used_services": [], "service": "television"},
{"number": "123467890", "used_services": [], "service": "television"},
{"number": "123567890", "used_services": [], "service": "television"},
{"number": "124567890", "used_services": [], "service": "television"},
{"number": "1234567890", "used_services": [], "service": "television"},
{"number": "1234567890", "used_services": [], "service": "television"},
{"number": "1234562390", "used_services": [], "service": "television"},
{"number": "1234567891", "used_services": [], "service": "television"},

以后我会在used_services中添加一个列表,如下所示:
x一个一个一个一个x一个一个二个x

pn9klfpd

pn9klfpd1#

将所有内容放入一个列表中,然后使用executemany(),这样它将成批插入它们。

params = [tuple(row[c] for c in columns) for row in traffic]
cursor.executemany('insert into numbers values(?,?,?)', params)
connection.commit()

相关问题