Django json dumps help -


i have following code need encoding json , appending data file, foo.json

here code:

user = request.user print 'user id ', user.id // 83 sour = json.dumps({"toast" : [{"uid" : user.id }]}) print 'sour toast: ', sour.toast # i'm getting error: attributeerror: 'str' object has no attribute 'toast' 

basically want create json file contains user.id value can accessible front end through jquery.

if can me error i'm getting or tips on go after fix error, appreciate it.

json.dumps returns string. when do:

sour = json.dumps({"toast" : [{"uid" : user.id }]}) print sour 

simple prints string looks this:

{"toast" : [{"uid" : user.id }]} 

not actual object or dict can individual values from, string can print or write file or whatever else want strings. looks want print this:

source toast: [{"uid":83}] 

to you'd want following:

sour = json.dumps([{"uid":83}]) print "sour toast: ", sour 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -