场景:今天使用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. 自底向上构建知识图谱全过程
  2. Java管理Cookie增删改查操作
  3. EL之RF(随机性的Bagging+DTR):利用随机选择属性的bagging方法解决回归(对多变量的数据集+实数值评分预测)问题
  4. Spring boot格式化器
  5. BZOJ #3166. [Heoi2013]Alo(可持久化trie树+set)
  6. 问一个网络工程师是怎么崩溃之一的?
  7. 【2019浙江省赛 - K 】Strings in the Pocket(马拉车,思维)
  8. leetcode题解48-旋转图像
  9. Oracle性能优化3-sql优化一定要等价
  10. 手机平板巡检系统,掀起设备巡检的第2次革命
  11. Linux安装SQLite轻量级数据库
  12. php autoload 性能,PHP __autoload()方法真的影响性能吗?
  13. [Angular2 Animation] Control Undefined Angular 2 States with void State
  14. 路径中,连续多个目录分隔符不影响,仍按照一个处理
  15. 技术对接场景,打破创新窘境
  16. 淘宝新规:售假者严重违规须缴纳100%保证金
  17. Cadence Allegro学习之铜皮(走粗线)的使用方法+罐铜+铜皮切割
  18. Apple让我明白坚持的意义
  19. Android手表商场项目总结
  20. android型号的平板电脑,AUTOID Pad /Air-(win)/Air-(android)工业级平板电脑

热门文章

  1. 两个国家级宝藏网站推荐
  2. 使用相关jar包爬取网页数据
  3. html超链接怎么设置到下一页,怎么设置超链接到一个网页
  4. 设置网站服务器,网站服务器如何设置
  5. 国外免费VPS主机的使用注意事项,这篇文章为你解答疑惑
  6. 基于Auto.js的支付宝批量自动转账脚本
  7. 由鸣人的螺旋丸想到的
  8. 文件服务器单向传输数据,一种单向文件传输方法及实现该传输方法的服务器
  9. orb slam3之BA部分源码解读
  10. C语言-计算圆面积。