python类转换为字典

import json

class User(object):

    def __init__(self, username, theme,image):
        self.username = username
        self.theme = theme
        self.image = image

@app.route("/me1")
def me_api1():
    user = User('wxy','theme','image')
    return json.dumps(user, default=lambda obj: obj.__dict__)

  类转换为字典

 json.dumps(user, default=lambda obj: obj.__dict__)

  

posted @ 2020-09-18 12:31  shiningrise  阅读(2103)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css