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