Django newbie question
I have this code :
def encode_myway(obj):
if isinstance(obj, User):
data = dict()
data['username'] = obj.username
data['code'] = obj.code //a number = 30
return data
I'm serializing for json using simplejson.dumps(resp, default=encode_myway)
the problem I have is that code (an integer) is equal to NULL but if I use serializers.serialize("json", [resp,])
I got a lot of garbage in my开发者_如何学C json but the integers are correct.. for garbage I refer to something like this :
"[{\"pk\":\29,\\"model\":\\"smapp.userprofile\",\\"fields\":\{\"city\":\\"barcelona\", ... }}]"
You seem to be double-encoding. You don't show where resp
comes from, but it seems to be JSON already.
精彩评论