场景:今天使用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相关推荐

  1. 成功解决Python中出现的TypeError: object of type 'zip' has no len()

    成功解决Python中出现的TypeError: object of type 'zip' has no len() 不罗嗦,直接解决问题! 目录 解决问题 解决思路 解决方法 解决问题 TypeEr ...

  2. 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== ...

  3. 【文件处理】——字典写入json文件或TXT文件,读取文件中的字典TypeError: Object of type ‘ndarray‘ is not JSON serializable错误解决方法

    目录 一.将字典写入json文件 二.json文件中读取字典 三.将字典写入TXT文件中 四.从TXT中读取字典 五.解决字典含数组存入json文件失败的方法 1.存入前将数组变成列表 2.扩展类方法 ...

  4. TypeError: Object of type 'datetime' is not JSON serializable

    json序列化时间对象的时候报错: TypeError: Object of type 'datetime' is not JSON serializable 解决办法 重写json序列化类 # -* ...

  5. 记录: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} ...

  6. python3运行报错:TypeError: Object of type ‘type‘ is not JSON serializable解决方法(详细)

    python3运行报错:TypeError: Object of type 'type' is not JSON serializable解决方法(详细) 参考文章: (1)python3运行报错:T ...

  7. 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 ...

  8. 成功解决TypeError: object of type ‘int‘ has no len()

    成功解决TypeError: object of type 'int' has no len() 目录 解决问题 解决思路 解决方法 解决问题 TypeError: object of type 'i ...

  9. 成功解决TypeError: Object of type 'ndarray' is not JSON serializable

    解决问题 TypeError: Object of type 'ndarray' is not JSON serializable 解决方法 def default(self, obj):if isi ...

最新文章

  1. java回顾之继承 二
  2. Java自学手记——servlet3.0新特性
  3. Android数据库高手秘籍
  4. mysql与hive比较
  5. why my own list cannot automatically scroll to load oData
  6. 修改shape数据 小数位数_【数据管理】Excel实用精华
  7. Qualitative and Quantitative
  8. 如何计算列表项的出现?
  9. This iPhone is running iOS 12.2(16E227),which may be supported by this version of Xcode
  10. List集合操作二:排序
  11. 自底向上的归并排序算法
  12. RabbitMQ(一) | MQ技术对比,以及对RabbitMQ五种消息模型的使用
  13. linux 下载工具
  14. Mask R-CNN网络详解
  15. Mysql 索引为啥使用B+树?不用哈希或B树?红黑树?
  16. Tensorflow + 基于CNN神经网络的面部表情识别
  17. python SSLError HTTPSConnectionPool bad handshake
  18. 解决CENTOS下There are no enabled repos.的问题
  19. @Transactional 详解 示例
  20. 微软正式发布Chromium Edge开发预览版

热门文章

  1. Ubuntu如何突出重围?
  2. ORACLE数据库查询太慢,内存溢出了
  3. 无人机地面站源码搭建环境(qt版)记录
  4. PS封装H264码流
  5. FGW 项目开发遇到问题
  6. 2012年3月份第4周51Aspx源码发布详情
  7. 腾讯副总裁王巨宏:微信校园卡可以解决课堂点名的问题
  8. PCB对点之Mark点检测
  9. 腾讯全球合作伙伴大会腾讯云火爆专场
  10. 数据库协作运维大势所趋