简体   繁体   中英

How to format Python MySQLdb SELECT result into json.dumps, key-value pairs to be present in json object

请举个例子,我发现很难使Mysql db结果成为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()]

Now you should get python list(dictionary).You can appl this in your database.

Hope this will help for you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM