0

I have an object which contains another object. I want to encode it and then decode with jsonpickle.

Encoded Ok. But when i trying decode encoded string it still consist jsonpickle marks in it.
So variable decode_testk not equal to testk.
decode_testk.boxes[0] is still encoded object.

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'}
Oleg
  • 1
  • 3
  • 1
    What is your question? Yes, when you encode and decode a dictionary as a jsonpickle you are returned with a different object. What is it you want to know about this process? Or, what do you want to be produced? – MrAlias Jul 11 '14 at 17:40
  • I have a variable. I want to encode it, save in mongo database. Then get it back, decode and use. I thought i can do it with jsonpickle. But when i trying to decode it, i get not the same variable which i have originally. Some parts of variable still in jsonpickle reprasentation. Can i do it with jsonpickle and how? Or it will better to use another way? – Oleg Jul 13 '14 at 16:54

0 Answers0