开发者

Remove unicode strings in rendered template

I'开发者_运维技巧m trying to return a json like object under this address:

http://ntt.vipserv.org/data/shows

but as a result I'm getting :

{'1': {'url': u'http://www.rte.ie/tv/crimecall/', 'image': u'http://img.rasset.ie/0002c8d0-250.jpg', 'id': u'2', 'name': u'Crimecall'}}

How to get rid fo the unicode strings ?

My code:

objects = Show.objects.all()
i = 0
dict = {}
small_dict = {}
for o in objects:
    small_dict = {'id': o.id.decode('ascii'), 'url': o.url.decode('ascii'), 'name': o.name.decode('ascii'), 'image': o.image.decode('ascii')}
    dict[str(i+1)] = small_dict
    small_dict = {}


I'd suggest using the json module instead of trying to write a JSON encoder yourself. This will correctly format the strings in double quotes and without the u in front of the string.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜