deserialize json to python object

1,971 views
Skip to first unread message

Rein Petersen

unread,
Feb 10, 2009, 4:23:28 AM2/10/09
to Google App Engine
what is wrong with this:

from django.utils import simplejson
...
obj = simplejson.loads("{'id':'KS1-0','type':'activity','units':
1,'priceper':450}")
self.response.out.write("<p>" + obj.type + "</p>");

I get the error:
File "C:\Program Files\Google\google_appengine\lib\django\django\utils
\simplejson\decoder.py", line 127, in JSONObject
raise ValueError(errmsg("Expecting property name", s, end))
ValueError: Expecting property name: line 1 column 1 (char 1)

What am I not understanding? Maybe my eyes are tired...

Thanks in advance :)

livibetter

unread,
Feb 10, 2009, 4:41:01 AM2/10/09
to Google App Engine
On Feb 10, 5:23 pm, Rein Petersen <rein.peter...@gmail.com> wrote:
>     obj = simplejson.loads("{'id':'KS1-0','type':'activity','units':
> 1,'priceper':450}")

The string of JSON is wrapped with double quote. ( http://json.org/ )

This will work

Rein Petersen

unread,
Feb 10, 2009, 12:33:34 PM2/10/09
to Google App Engine
Hey thanks for the reply - that was the problem. Thanks again :)

notsobad

unread,
Feb 10, 2009, 4:38:28 AM2/10/09
to Google App Engine
I use this
a=eval("{'id':'KS1-0','type':'activity','units':1,'priceper':450}")
print a['type']

On Feb 10, 5:23 pm, Rein Petersen <rein.peter...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages