如何从Python返回值作为JSON?

Sus*_*ire 9 python ajax jquery json

我从如下的jQuery文件发送ajax请求,该文件需要JSON中的响应.

jQuery.ajax({
    url: '/Control/getImageDetails?file_id='+currentId,
    type: 'GET',
    contentType: 'application/json',
    success: function (data){
        alert(data);
    }
 });
});
Run Code Online (Sandbox Code Playgroud)

在Python上,我发送了对Ajax请求的响应:

 record = meta.Session.query(model.BannerImg).get(fid)
 return_info = [record.file_id, record.filename, record.links_to]
 return result_info
Run Code Online (Sandbox Code Playgroud)

这会以纯文本形式返回参数,因此无法将其视为不同的值.我相信当JSON解决这个问题时发送来自python的响应.我以前使用过JSON.如何以JSON形式返回响应?

ira*_*ycd 13

return json.dumps(return_info)

主要问题是

 return_info = [record.file_id, record.filename, record.links_to]
Run Code Online (Sandbox Code Playgroud)

因为JSON格式一般都是这样的

例:

json.dumps({'file_id': record.file_id, 'filename': record.filename , 'links_to' : record.links_to})
Run Code Online (Sandbox Code Playgroud)

[object Object]如果您使用,您将收到的信息alert(data)

因此,alert(data.file_id);如果您使用该示例,请使用