import json d=dict(name=
"cui",age=20,score=88) print json.dumps(d) l=[
"cui",20,88] print json.dumps(l) class Student(object): def __init__(self): super(Student,
self).__init__() self.age=20 self.name="cui" self.score=88 print json.dumps(Student(),default=lambda obj:obj.__dict__) json_str=
'{"age": 20, "score": 88, "name": "cui"}' d= json.loads(json_str)
print d json_str=
'["cui", 20, 88]' l=json.loads(json_str)
print l json_str=
'{"age": 20, "score": 88, "name": "cui"}' def dict2Student(d): s=Student() s.name=d[
"name"] s.age=d[
"age"] s.score=d[
"score"] return s student=json.loads(json_str,object_hook=dict2Student)
转载于:https://www.cnblogs.com/liguangxu/p/5506990.html