1. new一个class,设置好自己的value
2. 然后调用实例名.dict
3. 然后使用json模块的json.dumps() ,此函数返回你想要的json数据
示例:
class Test(object):
def __init__(self, age):
self.age = age
a = Test(11)
a.name = 'xiaoming'
print(a)
<__main__.aa object at 0x7f54723f40b8>
print(a.__dict__)
{'age': 11, 'name': 'xiaoming'}
print(json.dumps(a.__dict__))
{"age": 11, "name": "xiaoming"}