我从django代码JSON返回,如下所示:
我的django代码:
objs = AccessInfo.objects.filter(~Q(weblink=''))
return HttpResponse(serializers.serialize('json', objs), mimetype="application/json")
我在前台得到的是:
我希望能够在前端用javascript迭代这些JSON对象,并在一些html中显示每个fields
值。在
如果我alert(data)
,我得到[ Object, Object ]
。在
我试过$.parseJSON(data)
,但我得到了:
我该怎么做?在
更新:
我的js接收的数据如下:
$.ajax({
url: '/get_book_access_downloads/',
type: 'get',
data: {bookid:bookid},
dataType: 'json'
}).done(function(data){
// to do
});
您的数据已被解析。您有一个JavaScript对象列表,不需要再次解析它。在
您使用jQuery来加载数据,当您在
$.ajax()
调用上使用dataType: 'json'
时,jQuery会为您解析JSON响应;如果您省略了该参数,jQuery将自动检测到JSON响应,并按其mime类型为您解码。在有关} documentation :
dataType
选项,请参见^{您有一个包含2个结果的列表;每个结果都是一个JavaScript对象,带有键},而{}值是另一个包含每个模型字段的对象。在
pk
、model
和{相关问题 更多 >
编程相关推荐