python如何把json字符串转换成自定义的对象
class Result(object):
def __init__(self, code,message, response=[]):
self.code=code
self.message = message
self.response = response
这是json字符串:str: {"code":200,"message":"发送成功","response":[{"code":2,"message":"xxxxxxxx","mobile":"xxxxxx","taskId":null},{"code":2,"message":"xxxxxx","mobile":"xxxxxx","taskId":null}]}
json.loads()
那加个 object_hook
看了下你的问题不需要object_hook..
直接简单粗暴
update: 修改一下格式 然后你
response=[]
这种写法是不推荐的所以最后可用的结果: