XXX is not JSON serializable 另类解决方式
来源:互联网 发布:vs2017 golang 编辑:程序博客网 时间:2024/04/28 00:48
这个问题在网上看了很多方法,但就是和我的错误对不上,没办法只好不停找寻,最终发现了一个合适的方式,其中原因我也说不清,也许其他人也会遇到,放出来让大家瞧瞧吧
我之所以会遇到这个问题我认为不是代码问题。我把项目部署到Linux上时遇到这个错误,但在windows上这个问题不存在。
results = sockQuery(query) //zmq 通信获得了json数组大概是这样[{‘city’:'beijing','dist':0.9,'Nx':1,'Ny':2,'mark':1},{‘city’:'shanghai','dist':0.8,'Nx':3,'Ny':2,'mark':1},......]
result=eval(repr(results)) //关键就是这句了,从新获取json数组,其实这句该怎么讲才有道理我还不知道,但接下来就是没报错。。。。。
json = simplejson.dumps({'results':result,'retrieveStyle': 'distRetrieve', 'status': 'ok'}) //以前一直报错的地方就是这了,我的错一直是1 is not JSON serializable 这个1 在results里面
return HttpResponse(json, mimetype='application/json')
以上代码是python (django)前后端数据交互时用到的,因为要把结果传回web前端,所以用到了simplejson.dumps
django 版本是1.6.11,所以更高版本应该是json.dumps
仅供参考,不喜勿喷
- XXX is not JSON serializable 另类解决方式
- 【已解决】Object of type 'range' is not JSON serializable
- 【已解决】Object of type 'QuerySet' is not JSON serializable
- Django笔记---项目报错之“xxx is not JSON serializable”
- flask return jsonify 时 报 xxx is not JSON serializable问题解决
- 解决图片对象不能json序列化问题:<ImageFieldFile: image/background_IXSZChD.jpg> is not JSON serializable
- TypeError: ObjectId('') is not JSON serializable
- datetime.datetime() is not JSON serializable
- [Python]json 错误xx is not JSON serializable
- python datetime.datetime is not JSON serializable 报错问题解决
- python datetime.datetime is not JSON serializable 报错问题解决
- lightbird json not JSON serializable
- 解决Android Studio打包报错"xxx"is not translated in "xxx"(xxx)[Missing Translation]
- Django自定义数据段问题即 [] is not JSON serializable(数组非JSON序列化)
- xxx is not maped
- TF53011 xxx is not a licensed user错误的解决
- XXX is not in the sudoers file解决
- XXX is not in the sudoers file解决
- Ceilometr: 2 、Cnocchi技术介绍
- KVC
- solr5.3.1 集成IK中文分词器
- 搜索二叉树
- Spring MVC 入门示例讲解
- XXX is not JSON serializable 另类解决方式
- KVO
- C++中的enum类型
- java 基础运算
- 【SSH网上商城项目实战27】域名空间的申请和项目的部署及发布
- 记录自己有用的链接
- ACM个人模板
- NSNotification
- C++之多重继承