我有一个包含另一个对象的对象。 我想编码,然后用jsonpickle解码。
编码好了。但是当我尝试解码编码的字符串时,它仍然包含jsonpickle标记。
因此变量decode_testk不等于testk
decode_testk.boxes [0]仍然是编码对象。
In [79]: qr = focr_qrcode.formForQRCodeRead()
In [80]: qr.__dict__
{'anchors_size': (157, 151), 'size': (1640, 2320), 'boxes':[<freaderarc.freader.model.ImageQRCodeBox instance at 0x249d4d0>], 'name': 'QRCode reader', 'description': 'recognize QRCode'}
In [81]: qr.boxes[0].__dict__
{'name': 'QRCODE', 'rect': (0, 0, 0, 0), 'area': (0, 0, 600, 600)}
In [82]: testk = jsonpickle.encode(qr)
In [83]: testk
'{"py/object": "freaderarc.freader.model.FormModel", "anchors_size": {"py/tuple": [157, 151]}, "name": "QRCode reader", "description": "recognize QRCode", "boxes": [{"py/object": "freaderarc.freader.model.ImageQRCodeBox", "name": "QRCODE", "rect": {"py/tuple": [0, 0, 0, 0]}, "area": {"py/tuple": [0, 0, 600, 600]}}], "size": {"py/tuple": [1640, 2320]}}'
In [84]: decode_testk = jsonpickle.decode(testk)
In [85]: decode_testk
<freaderarc.freader.model.FormModel instance at 0x249d638>
In [86]: decode_testk.__dict__
{'anchors_size': (157, 151), 'size': (1640, 2320), 'boxes': [{'py/object': 'freaderarc.freader.model.ImageQRCodeBox', 'name': 'QRCODE', 'rect': {'py/tuple': [0, 0, 0, 0]}, 'area': {'py/tuple': [0, 0, 600, 600]}}], 'name': 'QRCode reader', 'description': 'recognize QRCode'}