Discuss / Python / json序列化

json序列化

Topic source

Aspire

#1 Created at ... [Delete] [Delete and Lock User]
import json
d = dict(age=132,name='张三')
class Student(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age
        pass
student = Student('张三',20)
s = json.dumps(student, default= lambda self: self.__dict__)
s = json.loads(s, object_hook = lambda df: Student(df['name'], df['age']))
print(s)

  • 1

Reply