python json转换异常:“In order to allow non-dict objects to be serialized..."
2016-07-14 14:46
726 查看
看 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)
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)
相关文章推荐
- Effetive Objective - C 1.Objective 概述
- 【转载】V$LOCK 和 V$LOCKED_OBJECT 的区别
- 《OpenGL ES 2.0 Programming Guide》第8章 “最简单的Vertex Buffer Object”示例代码【C语言版】
- HTML <object> 标签
- PHP Object 转 Array,Json 转 Array
- JSONObject,JSONArray取值
- ScriptableObject
- Objective-C Posing
- Objective-C是动态语言吗?为什么?
- 深入Objective-C的动态特性(基于runtime实现)
- JAVA源码剖析之---Object类(三)---toString,wait,notify,notifyAll,finalize方法的使用
- iOS开发实用技巧—Objective-C中的各种遍历(迭代)方式
- React Native ListView的Item设置点击事件时null is not an object
- IOS-usr/include-objc-NSObject.h-ARC与非ARC
- 异常
- 【Git】Git hangs while unpacking objects (Windows)
- wait()、notify()和notifyAll()是 Object类 中的方法
- 在JAVA中使用JSONObject生成json
- [精通Objective-C]归档和序列化
- 补间动画,属性动画实现购物车添加动画