将模型用flask封装,返回json时报错:TypeError: Object of type 'int32' is not JSON serializable

网上搜索出的解决方案:重写json.JSONEncoder

class MyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, numpy.integer):
return int(obj)
elif isinstance(obj, numpy.floating):
return float(obj)
elif isinstance(obj, numpy.ndarray):
return obj.tolist()
else:
return super(MyEncoder, self).default(obj)
json.dumps(data,cls=MyEncoder)

TypeError: Object of type 'int32' is not JSON serializable ——已解决的更多相关文章

  1. TypeError: Object of type 'int32' is not JSON serializable

    将模型用flask封装,返回json时报错:TypeError: Object of type 'int32' is not JSON serializable 网上搜索出的解决方案:重写json.J ...

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

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

  3. TypeError: Object of type 'int64' is not JSON serializable

    错误类型:TypeError: Object of type 'int64' is not JSON serializable 错误场景:对Numpy和Pandas结果进行json.dumps报错 错 ...

  4. TypeError: Object of type 'ListSerializer' is not JSON serializable

    问题: 解决:ser.data是json数据,你想要的

  5. typeerror object of type ‘decimal‘ is not json serializable jsonify

    当使用flask的jsonify返回json数据时,由于数据库有些字段类型使用decimal,而jsonify无法处理 解决方案 导入下面的包即可解决 pip install simplejson

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

    我的描述:我在flask框架中引用orm查数据库并返回数据,出现此类问题,如下图: 解决方案: 1.从表面意思看,就是说datetime时间类型无法被序列化.于是我百度了网上的同事的解答,大多说是时间 ...

  7. celery 4.1下报kombu.exceptions.EncodeError: Object of type 'bytes' is not JSON serializable 处理方式

    #python代码如下 from celery import Celeryimport subprocess app = Celery('tasks', broker='redis://localho ...

  8. Object of type 'ListSerializer' is not JSON serializable “listserializer”类型的对象不可JSON序列化

    Object of type 'ListSerializer' is not JSON serializable “listserializer”类型的对象不可JSON序列化 一般原因为 序列化的对象 ...

  9. Object of type 'ndarray' is not JSON serializable

    Object of type 'ndarray' is not JSON serializable import numpy as np import json arr=np.asarray([345 ...

随机推荐

  1. Pecan

    什么是peacn Pecan是一个轻量级的基于Python的Web框架, Pecan的目标并不是要成为一个“full stack”的框架, 因此Pecan本身不支持类似Session和Database ...

  2. 剑指 offer set 26 不用加减乘除做加法

    总结 1. Leetcode 上有一道题, 是不用乘除做乘法, 那道题算是背包问题的变形 2. 不用加减乘除, 还可以用移位操作 3. 将数字转成二进制格式, 然后运用二进制亦或, 移位运算解决 3. ...

  3. leetcode -- Permutations II TODO

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  4. ImageLoader must be init with configuration before using

    遇到上面的问题是没有全局初使化ImageLoader,我是在Application中配置了ImageLoaderConfiguration 解决的,当然还有官方的写法 public class MyA ...

  5. phpredis 中文手册和redis 教程

    phpredis 中文手册  :   http://www.cnblogs.com/zcy_soft/archive/2012/09/21/2697006.html 手册: http://www.cn ...

  6. 【BZOJ3622】已经没有什么好害怕的了 容斥+DP

    [BZOJ3622]已经没有什么好害怕的了 Description Input Output Sample Input 4 2 5 35 15 45 40 20 10 30 Sample Output ...

  7. 如何使用iOS 开发证书 和 Profile 文件

    如果你想在 iOS 设备(iPhone/iPad/iTouch)上调试, 需要有 iOS 开发证书和 Profile 文件. 在你拿到这两个文件之后,该如何使用呢? 证书使用说明: 1.  iOS 开 ...

  8. JDBC通用DAO

    dbcBaseDao接口,内容如下: package com.sun4j.core.jdbc.dao; import java.io.Serializable; import java.util.Li ...

  9. kafka服务器搭建与测试

    kafka服务器搭建 kafka自身集群信息的管理以及对producer和consumer的信息管理是通过zookeeper实现的,zookeepr是kafka不可分割的一部分,所以搭建zookeep ...

  10. 05.Curator分布式锁

        锁:分布式的锁全局同步,这意味着任何一个时间点不会有两个客户端都拥有相同的锁. 1.可重入锁Shared Reentrant Lock     首先我们先看一个全局可重入的锁(可以多次获取,不 ...