TypeError: Object of type 'ndarray' is not JSON serializabl;TypeError: Object of type 'int64' is not

迎月兮

关注

阅读 144

2022-10-26


1 . python使用​​json.jsonify​​​ 将结果转为json格式时,爆出如上​​TypeError: Object of type 'ndarray' is not JSON serializable​​​错误。
(flask)代码如下:

@app.route('/predict/counts')
def predcitcounts():
index, count = data_analyse.time_counts()
res={}
res['index']=index
res['count']=count ##1
return

其中,index,count类型分别为:​​<class 'list'> <class 'numpy.ndarray'>​​。

2 . 将​​##1​​​处代码改为​​res['count']=list(count)​​​,则报错 “​​TypeError: Object of type 'int64' is not JSON serializable​​”。

3 . 故​​##1​​修改为:

res['count']=[str(i) for i in count]

4 . 返回json数据如下:

TypeError: Object of type


精彩评论(0)

0 0 举报