解决python报错Object of type xxx is not JSON serializable
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
免费下载资源
·
Object of type Ip xxx is not JSON serializable
其中xxx为自定义类的对象,调用json.dumps报了错。
怎么解决呢? 很简单,将对象改为dict结构再转就OK了!
示例:要转的对象为obj
convert = dict()
convert ['a'] = obj.a
convert ['b'] = obj.b
result = json.dumps(convert)
常用类型到json的转换规则如下:
Python | JSON |
---|---|
dict | object |
list, tuple | array |
str, unicode | string |
int, long, float | number |
True | true |
False | false |
None | null |
GitHub 加速计划 / js / json
41.72 K
6.61 K
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
960b763e
2 个月前
8c391e04
5 个月前
更多推荐
已为社区贡献8条内容
所有评论(0)