Encapsulate the model with flash and return JSON with error: typeerror: object of type ‘int32’ is not JSON serializable
Solution found on Internet: Rewrite json.jsonecoder
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)
Customer service:
https://www.cnblogs.com/lyq-bk1/p/9597172.html
Similar Posts:
- [Solved] Python Error: datetime.datetime is not JSON serializable
- TypeError: Object of type ‘datetime‘ is not JSON serializable [Solved]
- [Solved] Tensorflow Error: ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)
- Python JSON error json.decoder.jsondecodeerror Chinese
- Tensorflowcenter {typeerror} non hashable type: “numpy. Ndarray”
- Python bug problems and solutions sorted out in recent days
- Python: json:json.decoder.JSONDecodeError: Invalid control character at: line 2 column 18 (char 19)
- Python TypeError: not all arguments converted during string formatting
- [Solved] TypeError: string indices must be integers, not str
- [Solved] net.sf.json.JSONException: java.lang.ClassCastException: JSON keys must be strings.