【发布时间】:2021-11-10 11:02:14
【问题描述】:
我有一个方法可以进行一些计算,并且必须返回一个字典,如下面的代码部分所示。 该方法无法返回字典,因为它包含非序列化数据。 我尝试按照以下链接中的说明对其进行编码 https://pynative.com/online-python-code-editor-to-execute-python-code/ 还有她 TypeError: Object of type 'float32' is not JSON serializable
但我仍然收到相同的错误消息。 请告诉我如何解决这个问题
代码:
resultsDict = {
"pixelsValuesSatisfyThresholdInWindowSegment":json.dumps(numpyData,cls=NumpyArrayEncoder),
...
...
...
}
return resultsDict
错误信息
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type float32 is not JSON serializable
【问题讨论】:
-
也许你会找到一些东西here
-
分享
NumpyArrayEncoder和numpyData