如何将JSON封装在括号中?
我有这段代码:
objects = Event.objects.all()
i = 0
dict = {}
small_dict = {}
for o in objects:
small_dict = {'id': o.id, 'url': o.url, 'name': o.name, 'image': o.image}
dict[str(i+1)] = small_dict
small_dict = {}
return HttpResponse(
simplejson.dumps(dict),
content_type = 'application/javascript; charset=utf8'
)
它给了我这个:
{"1": {"url": "http://www.rte.ie/tv/crimecall/", "image": "http://img.rasset.ie/0002c8d0-250.jpg", "id": 2, "name": "Crimecall"}}
我如何进一步将其封装在 ()
括号之间?因为如果没有它们,我在 php 中解析它们时会出错。
I have this code :
objects = Event.objects.all()
i = 0
dict = {}
small_dict = {}
for o in objects:
small_dict = {'id': o.id, 'url': o.url, 'name': o.name, 'image': o.image}
dict[str(i+1)] = small_dict
small_dict = {}
return HttpResponse(
simplejson.dumps(dict),
content_type = 'application/javascript; charset=utf8'
)
and it gives me this :
{"1": {"url": "http://www.rte.ie/tv/crimecall/", "image": "http://img.rasset.ie/0002c8d0-250.jpg", "id": 2, "name": "Crimecall"}}
How I can further encapsulate it between ()
parentheses ? Because without them I'm getting error when parsing them in php.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以这样做,但现在在浏览器中看不到。如果这不是问题的话,代码如下:
You can do it this way, but it's not viewable in browser now. I'f that's not a problem, here's the code :