【发布时间】:2019-09-26 15:04:03
【问题描述】:
我使用 python 和 mysql.connector 这是我的代码
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM table")
myresult = mycursor.fetchall();
json_data=[]
for x in myresult:
json_data.append(x)
print(json.dumps(json_data))# CREATE JSON
然后给我结果:
[[1, 61, 8585, "80000000"], [3, 61, 5151, "200"], [4, 61, 8585, "20"]]
但我需要这个:
{
"data": [
{
"id": "1",
"sample": "61",
"Price": "80000000",
"name": "----"
},
{
"id": "3",
"sample": "61",
"Price": "200",
"name": "ali"
}
]
}
我能做什么? 感谢您的帮助:)
【问题讨论】: