在开发django项目时,后台使用的mysql数据库,查询的sql返回时报错:TypeError: Object of type Decimal is not JSON serializable
原因分析:主要是查询返回的字段中存在decimal数据
解决办法:将数据转换成字符串即可 cast (字段 as char)
select
cast(t2.total as char) total
from table
在开发django项目时,后台使用的mysql数据库,查询的sql返回时报错:TypeError: Object of type Decimal is not JSON serializable
原因分析:主要是查询返回的字段中存在decimal数据
解决办法:将数据转换成字符串即可 cast (字段 as char)
select
cast(t2.total as char) total
from table