Python TypeError: Object of type ‘Decimal‘ is not JSON serializable 类型错误 无法json
场景:今天使用python 查询了一个MYSQL 数据库的信息 数据库的字段为decimal 类型
我将结果进行json.dumps
报错 TypeError: Object of type 'Decimal' is not JSON serializable
经过分析 那个decimal的类型 它类型无法进行json 后面使用下面语句进行转化,一切OK 代码如下:
Decimal类型数据的处理
对于Decimal
类型的数据我们可以利用Python的decimal模块
先将其转为str
:
import decimal
price = str(decimal.Decimal(price).quantize(decimal.Decimal('0.00')))
然后把得到的结果再进行序列化即可。
Python TypeError: Object of type ‘Decimal‘ is not JSON serializable 类型错误 无法json相关推荐
- 成功解决Python中出现的TypeError: object of type 'zip' has no len()
成功解决Python中出现的TypeError: object of type 'zip' has no len() 不罗嗦,直接解决问题! 目录 解决问题 解决思路 解决方法 解决问题 TypeEr ...
- python 函数报错TypeError: object of type 'int' has no len()
函数源码 _times = 0 def hannuota(nlist,mfrom,mpass,mto):global _timesn=len(nlist)#n=nlist._length_if n== ...
- 【文件处理】——字典写入json文件或TXT文件,读取文件中的字典TypeError: Object of type ‘ndarray‘ is not JSON serializable错误解决方法
目录 一.将字典写入json文件 二.json文件中读取字典 三.将字典写入TXT文件中 四.从TXT中读取字典 五.解决字典含数组存入json文件失败的方法 1.存入前将数组变成列表 2.扩展类方法 ...
- TypeError: Object of type 'datetime' is not JSON serializable
json序列化时间对象的时候报错: TypeError: Object of type 'datetime' is not JSON serializable 解决办法 重写json序列化类 # -* ...
- 记录:TypeError: Object of type int32 is not JSON serializable。
rect_list = list()...rect_list.append(rect1)rect_list.append(rect2)...rsp = {'rect-list': rect_list} ...
- python3运行报错:TypeError: Object of type ‘type‘ is not JSON serializable解决方法(详细)
python3运行报错:TypeError: Object of type 'type' is not JSON serializable解决方法(详细) 参考文章: (1)python3运行报错:T ...
- Flask API TypeError: Object of type 'Response' is not JSON serializable
Flask API TypeError: Object of type 'Response' is not JSON serializable 错误代码: session['image'] = str ...
- 成功解决TypeError: object of type ‘int‘ has no len()
成功解决TypeError: object of type 'int' has no len() 目录 解决问题 解决思路 解决方法 解决问题 TypeError: object of type 'i ...
- 成功解决TypeError: Object of type 'ndarray' is not JSON serializable
解决问题 TypeError: Object of type 'ndarray' is not JSON serializable 解决方法 def default(self, obj):if isi ...
最新文章
- java回顾之继承 二
- Java自学手记——servlet3.0新特性
- Android数据库高手秘籍
- mysql与hive比较
- why my own list cannot automatically scroll to load oData
- 修改shape数据 小数位数_【数据管理】Excel实用精华
- Qualitative and Quantitative
- 如何计算列表项的出现?
- This iPhone is running iOS 12.2(16E227),which may be supported by this version of Xcode
- List集合操作二:排序
- 自底向上的归并排序算法
- RabbitMQ(一) | MQ技术对比,以及对RabbitMQ五种消息模型的使用
- linux 下载工具
- Mask R-CNN网络详解
- Mysql 索引为啥使用B+树?不用哈希或B树?红黑树?
- Tensorflow + 基于CNN神经网络的面部表情识别
- python SSLError HTTPSConnectionPool bad handshake
- 解决CENTOS下There are no enabled repos.的问题
- @Transactional 详解 示例
- 微软正式发布Chromium Edge开发预览版