[Tutor] python simplejson decoding

Arthur Mc Coy 1984docmccoy at gmail.com
Wed Mar 2 13:56:58 CET 2011


Hi all,



I'm trying an example (in attached file).

First, I create a list of 3 objects. Then I do:


PutJSONObjects(objects)
objects = GetJSONObjects()
PutJSONObjects(objects, "objects2.json")


1) PutJSONObjects(objects) method creates objects.json file (by default). It
works fine.
2) Then objects = GetJSONObjects() method get the file contents and return.

3) Finally the script fails on the third method PutJSONObjects(objects,
"objects2.json")
saying: AttributeError: 'dict' object has no attribute '__dict__'


That is true, because objects returned by GetJSONObjects() is not a list of
objects, but simple string....

So here is the question, please, how should I DECODE .json file into list of
python objects so that I will be able to put the copy of these objects into
a new file called objects2.json ?

simplejson <http://simplejson.github.com/simplejson/> docs are hard to
follow - without examples.



Please, help me. Be happy!

Bart
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110302/e024baab/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cache.py
Type: application/octet-stream
Size: 1423 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20110302/e024baab/attachment.obj>


More information about the Tutor mailing list