看 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)
python json转换异常:“In order to allow non-dict objects to be serialized...“
最新推荐文章于 2023-12-30 16:57:52 发布