如何在括号中封装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中解析它时会遇到错误。     
已邀请:
你可以这样做,但现在浏览器无法查看。我不是问题,这是代码:
callback = request.GET.get('callback', '')
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 = {}

response = simplejson.dumps(dict)
response = callback + '(' + response + ')';

return HttpResponse(response,
    mimetype ='application/json; charset=utf8')
    
JSON的MIME类型是“application / json”。 如果你在PHP中解析它有问题,那么这是一个PHP问题。不要在服务器端添加parens,而是在解析PHP中的字符串之前添加它们。我想你知道如何在PHP中连接,对吧?无论如何,我不明白你的问题是什么 - 你不使用json_decode?     

要回复问题请先登录注册