【发布时间】:2016-08-21 04:12:19
【问题描述】:
所以我有一些我想序列化为 JSON 的 python dict
{'someproperty': 0, 'anotherproperty': 'value', 'propertyobject': SomeObject(someproperty=0, anotherproperty=0)}
但是json.dumps 抛出一个TypeError: SomeObject(someproperty=0, anotherproperty=0) is not JSON serializable
那么我怎样才能正确序列化我的python dict?
【问题讨论】:
-
你不能有对象,即使 SomeObject 应该是一个 json 对象。像 {'someproperty': 0, 'anotherproperty': 'value', 'SomeJson':{'someproperty':0, 'anotherproperty':0}}
标签: python json python-2.7 dictionary typeerror