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__)

  

原文地址:https://www.cnblogs.com/shiningrise/p/13690595.html