python json转换异常:“In order to allow non-dict objects to be serialized..."

来源:互联网 发布:臭苋菜 知乎 编辑:程序博客网 时间:2024/06/17 02:00
看 JsonResponse(HttpResponse)类源码:知道是传入的数据不是字典类型,改为字典类型即可

    def __init__(self, data, encoder=DjangoJSONEncoder, safe=True,
                 json_dumps_params=None, **kwargs):
        if safe and not isinstance(data, dict):
            raise TypeError(
                'In order to allow non-dict objects to be serialized set the '
                'safe parameter to False.'
            )
        if json_dumps_params is None:
            json_dumps_param
s = {}
        kwargs.setdefault('content_type', 'application/json')
        data = json.dumps(data, cls=encoder, **json_dumps_params)
        super(JsonResponse, self).__init__(content=data, **kwargs)
0 0
原创粉丝点击