zoukankan      html  css  js  c++  java
  • json.dump throwing “TypeError: {…} is not JSON serializable”

    If it's a set type,then turn the set into list before serializing, or use a custom default handler to do so:

    1 def set_default(obj):
    2     if isinstance(obj, set):
    3         return list(obj)
    4     raise TypeError
    5 
    6 result = json.dumps(yourdata, default=set_default)

    If you want a dict type,Maybe it's not actually a dictionary; it's another mapping type that looks like a dictionary. Use type()to verify. Pass it to dict() to get a real dictionary from it.  

     1 def __init__(self, element):
     2     self.element = element
     3 
     4 def execute(self):
     5     if isinstance(self.element, dict):
     6         self.__iterate()
     7     else:
     8         return
     9 
    10 def __iterate(self):
    11     for key in self.element:
    12         if isinstance(self.element[key], <ClassName>):
    13             self.element[key] = str(self.element[key])
    14 
    15         node = NormalizeData(self.element[key])
    16         node.execute()
  • 相关阅读:
    好题Islands
    DB2的安装
    MariaDB存在的问题
    MariaDB 脚本
    SQL 执行顺序
    Maria数据库
    3 ignite windows 上安装
    Cassandra 学习七 cassandra研究
    Cassandra学习六 一些知识点
    Cassandra学习五 使用Key的正确姿势
  • 原文地址:https://www.cnblogs.com/sungyouyu/p/3745169.html
Copyright © 2011-2022 走看看