how do i get access to json data?

2010-11-23 Thread alecx
Hello django users, after several try outs, i am not able to figure out how to access data in a serialized object. E. g. how do I get the name "Douglas", "Adams" in the example: http://docs.djangoproject.com/en/dev/topics/serialization/#deserialization-of-natural-keys In javascript i can get e. g

Re: how do i get access to json data?

2010-11-23 Thread Li You
Maybe this is what you want: from json import JSONDecoder s = '''{ "pk": 1, "model": "store.book", "fields": { "name": "Mostly Harmless", "author": ["Douglas", "Adams"] } } ''' d = JSONDecoder().decode(s) print a['fields']['author'] On Tue, Nov 23, 2010 at 9:45 PM

Re: how do i get access to json data?

2010-11-23 Thread Li You
sorry but a mistake. On Tue, Nov 23, 2010 at 10:01 PM, Li You wrote: > Maybe this is what you want: > > from json import JSONDecoder > s = '''{ >    "pk": 1, >    "model": "store.book", >    "fields": { >        "name": "Mostly Harmless", >        "author": ["Douglas", "Adams"] >    } > } > ''' >

Re: how do i get access to json data?

2010-11-23 Thread alecx
Thanks for your answer Li. This solution works for python, I figured this out too. But how does this work inside a template with javascript? I use $.getJSON() inside the template to get the data. Inside the javascript I can access the data with: this.fields.name but this.fields.author does n