首页 > 解决方案 > 使用python的数据库

问题描述

我的数据 json :

在此处输入图像描述

我的代码:

import json
import re
import sqlite3

conn = sqlite3.connect('chinook.db')
cursor = conn.cursor()
c = conn.cursor()

with open('tem.txt', encoding='utf-8-sig') as json_file:
     data = json.load(json_file)
     for p in data:
         data[p] = re.sub("<[^>]+>", "", str(data[p]))
         print("%s: %s" % (p, data[p]))
         c.execute("insert INTO THINH (THONGTIN, ID) VALUES ('"+ data[p] +"','"+ p +"')")
 conn.commit()

我无法将 json 文件中的所有数据都放入我的数据库中?

在此处输入图像描述

标签: pythonpython-3.x

解决方案


推荐阅读