代码
import json
with open('D://gitxiangmu//exercises.json','r',encoding='utf-8') as load_f:
load_dict = json.load(load_f)
json_exercises = load_dict['exercises']
f = open('D://gitxiangmu//exercises.txt','a',encoding="utf-8")
for i in json_exercises:
print(i['id'])
id = i['id']
type = i['type_id']
subject = i['question']
answerA = i['answer_a']
answerB = i['answer_b']
answerC = i['answer_c']
answerD = i['answer_d']
answerE = i['answer_e']
answerF = ""
answer_true = i['real_answer']
sql = 'INSERT INTO `xxxxxx` VALUES (' + str(id) + ',\'' + type + '\'' + ',\'' + subject + '\'' + ',\'' + answerA + '\'' + ',\'' + answerB + '\'' + ',\'' + answerC + '\'' + ',\'' + answerD + '\'' + ',\'' + answerE + '\'' + ',\'' + answerF + '\'' + ',\'' + answer_true + '\'' + ');'
f.write(sql + "\r\n")
# sql = 'INSERT INTO `xxxxxx` VALUES (' + str(id) + ',\''+type+'\''+',\''+subject+'\''+',\''+answerA+'\''+',\''+answerB+'\''+',\''+answerC+'\''+',\''+answerD+'\''+',\''+answerE+'\''+',\''+answerF+'\''+',\''+answer_true+'\''+')'
# print(sql)
# f.write("text"+"\r\n")