【发布时间】:2018-01-22 22:09:45
【问题描述】:
当使用 jsonpickle 将对象序列化为 json 时,我注意到诸如 datetime 之类的对象会存储一次,然后将来使用会存储为引用值,例如 {"py/id":1}。是否可以存储实际值而不是参考?此引用似乎是隐藏的,并且在直接与数据库交互时会令人困惑。
例如。
class MyClass:
def __init__(self, eee):
now = datetime.datetime.utcnow()
self.ddd = now
self.ddd2 = now
self.ddd3 = now
Json 是
{"py/object": "__main__.MyClass", "py/state": {"ddd": {"py/object": "datetime.datetime", "__reduce__": [{"py/type": "datetime.datetime"}, ["B+IBFhYJCwx9oQ=="]]}, "ddd2": {"py/id": 1}, "ddd3": {"py/id": 1}, "eee": "fwaef"}}
【问题讨论】:
标签: python json jsonpickle