原文:http://blog.csdn.net/gqixf/article/details/78954021

class MyEncoder(json.JSONEncoder):def default(self, obj):if isinstance(obj, np.integer):return int(obj)elif isinstance(obj, np.floating):return float(obj)elif isinstance(obj, np.ndarray):return obj.tolist()else:return super(MyEncoder, self).default(obj)json_1 = {'num':1112, 'date':datetime.now()}
print(json.dumps(json_1, cls=MyEncoder))
# json.dumps(numpy.float32(1.2), cls=MyEncoder)
# json.dumps(numpy.arange(12), cls=MyEncoder)
# json.dump({'a': numpy.int32(42)},fp,cls=MyEncoder)

TypeError: Object of type 'float32' is not JSON serializable相关推荐

  1. 成功解决TypeError: Object of type 'ndarray' is not JSON serializable

    解决问题 TypeError: Object of type 'ndarray' is not JSON serializable 解决方法 def default(self, obj):if isi ...

  2. 记录:TypeError: Object of type int32 is not JSON serializable。

    rect_list = list()...rect_list.append(rect1)rect_list.append(rect2)...rsp = {'rect-list': rect_list} ...

  3. Flask API TypeError: Object of type 'Response' is not JSON serializable

    Flask API TypeError: Object of type 'Response' is not JSON serializable 错误代码: session['image'] = str ...

  4. 【文件处理】——字典写入json文件或TXT文件,读取文件中的字典TypeError: Object of type ‘ndarray‘ is not JSON serializable错误解决方法

    目录 一.将字典写入json文件 二.json文件中读取字典 三.将字典写入TXT文件中 四.从TXT中读取字典 五.解决字典含数组存入json文件失败的方法 1.存入前将数组变成列表 2.扩展类方法 ...

  5. labelme2coco问题:TypeError: Object of type 'int64' is not JSON serializable

    最近在做MaskRCNN 在自己的数据(labelme)转为COCOjson格式遇到问题:TypeError: Object of type 'int64' is not JSON serializa ...

  6. TypeError: Object of type 'datetime' is not JSON serializable

    json序列化时间对象的时候报错: TypeError: Object of type 'datetime' is not JSON serializable 解决办法 重写json序列化类 # -* ...

  7. TypeError: Object of type set is not JSON serializable

    今天运行flask项目突然报TypeError: Object of type set is not JSON serializable错误,上网搜了一下 该对象是set形式,json序列不支持,回到 ...

  8. 返回 JSON 格式数据报错:TypeError: Object of type set is not JSON serializable

    在做 flask 项目的时候需要返回一个 JSON 数据,运行的过程中却报错:TypeError: Object of type set is not JSON serializable 报错位置如下 ...

  9. Python TypeError: Object of type ‘Decimal‘ is not JSON serializable 类型错误 无法json

    场景:今天使用python 查询了一个MYSQL 数据库的信息  数据库的字段为decimal 类型 我将结果进行json.dumps 报错 TypeError: Object of type 'De ...

最新文章

  1. 人工智能的热望与冷思考 | 郭毅可院士:我们不要神化它
  2. 9、ctemplate文档,简记(2)
  3. DeviceEventEmitter 使用监听通知进行传值
  4. pay-as-you-go
  5. MongoDB 初体验:存储引擎 MMAPv1 与高内存消耗及升级迁移
  6. 【Eclipse】Eclipse中tomcat的Server配置(解决修改代码不断的重启服务器)以及设置tomcat文件发布位置与JSP编译位置查看...
  7. Zephyr_Bindings目录作用
  8. MyBatis的ResultMaps之一对多关系
  9. Machine Learning and Data Science 教授大师
  10. 关于图书馆占座问题的调查
  11. xlsxwriter设置列宽_Python3之excel操作xlsxwriter模块
  12. Web网站扫【小程序码】登录的技术实现
  13. mac中idea使用createNewFile创建文件
  14. 固态硬盘数据丢失了该怎么办
  15. Qualcomm QCA9379无线WiFi/蓝牙模块芯片参数介绍
  16. 读经典《C程序设计语言》(The C Programming Language)
  17. 学习SyntaxHighlighter
  18. 2017滴滴出行实习面试总结(测试岗,拿到offer)
  19. perc s100 linux,PERC S100_S300 配置手册
  20. sql实现多字段去重

热门文章

  1. html div最多50个字符,javascript-计算多少个字符(来自一个字符串)将适合一个div而没有使其换行?...
  2. linux查询超线程,【转】Linux下判断一台机器是多少路,多少核,是否超线程的方法...
  3. Design Pattern - Prototype(C#)
  4. java soap附件_java - 附件在SoapUI中工作,但在Java中不能使用SAAJ API吗? - 堆栈内存溢出...
  5. flux读取不到数据_spring-webflux两种开发模式,获取不到使用ajax的post提交的数据?...
  6. 气象gis 解决方案_杜邦可持续解决方案全方位智能化应急管理系统解决方案
  7. OAuth2 服务器Keycloak中的Realm
  8. 皮一皮:童话里都是骗人的...
  9. 一文搞懂 ThreadLocal 原理
  10. 用好这 12 款 Chrome 扩展,让你的「新标签页」变得好看又实用