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=[]
這種寫法是不推薦的所以最後可用的結果: