import numpy as np

import json

arr = np.asarray([345, 45])

result = {'name': 'test', 'num': arr}

json.dump(result)

报错:

TypeError: Object of type ndarray is not JSON serializable

解决办法:

result={'name':'text','num':arr.tolist()}
Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐