如何将 Python MySQLdb SELECT 结果格式化为 json.dumps,键值对出现在 json 对象中
How to format Python MySQLdb SELECT result into json.dumps, key-value pairs to be present in json object
请举个例子,我发现很难将 Mysql 数据库结果作为 jsonobject。
cur.execute('select title, text from posts order by id desc')
posts = [dict(title=row[0], text=row[1]) for row in cur.fetchall()]
现在你应该得到 python 列表(字典)。你可以在你的数据库中应用它。
希望这对您有所帮助
请举个例子,我发现很难将 Mysql 数据库结果作为 jsonobject。
cur.execute('select title, text from posts order by id desc')
posts = [dict(title=row[0], text=row[1]) for row in cur.fetchall()]
现在你应该得到 python 列表(字典)。你可以在你的数据库中应用它。
希望这对您有所帮助