class NpEncoder(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(NpEncoder, self).default(obj)
添加上面的代码 使用方法 with open('ec_dict1.json', 'w')as f: json.dump(data, f, ensure_ascii=False, cls=NpEncoder)