开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜