开发者

Django newbie question

开发者 https://www.devze.com 2023-02-10 07:41 出处:网络
I have this code : def encode_myway(obj): if isinstance(obj, User): data = dict() data[\'username\'] = obj.username

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

精彩评论

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