我有这个 swf(flash)文件,它提供需要发送到服务器的 json。
我写了一个非常简单的 jQuery:
function submitForm(swf_json) {
$('#swfjson').val(swf_json); #swfjson is an input of type hidden
$('#titleForm').submit();
}
swf将调用上面的submitForm,我会像往常一样在django中收到request.POST。
但是,django 将 swf_json
解释为字符串 “Object object”
>>>type(request.POST['swfjson'])
<type 'unicode'>
当然,我可以将 json 作为字符串传递给 View 函数。我觉得不太好。还有其他方法可以将 json 对象传递给 django View 吗?
最佳答案
您必须首先使用 https://github.com/douglascrockford/JSON-js 等库将您的 JavaScript 对象“序列化”为 JSON 字符串 (JQuery 中没有内置适当的函数。)
关于jquery - 如何通过表单元素传递 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2453175/