所以我送一个JSON看起来像这样:如何处理JSON来的QueryDict以JSON
[
{
"Datum": "textholder1",
"Bedrag": "",
"Rekening": "",
"Tegenrekening": "",
"Naam": "",
"Omschrijving": ""
},
{
"Datum": "textholder2",
"Bedrag": "",
"Rekening": "",
"Tegenrekening": "",
"Naam": "",
"Omschrijving": ""
}
]
要通过POST服务器,当我找回它,它看起来像这样:
{
"json[1][Omschrijving]": [""],
"json[1][Rekening]": [""],
"json[0][Datum]": ["textholder1"],
"json[1][Tegenrekening]": [""],
"json[0][Rekening]": [""],
"json[0][Bedrag]": [""],
"json[0][Naam]": [""],
"json[1][Naam]": [""],
"json[0][Tegenrekening]": [""],
"json[1][Bedrag]": [""],
"json[0][Omschrijving]": [""],
"json[1][Datum]": ["textholder2"]
}
因此,您可以看到它将内部对象转换为json[index]
而不是保持其格式。这是正常行为还是我在这里做错了?这是我如何检索数据:
inputData = request.POST
userDataList = dict(inputData.lists())
print userDataList # prints the funny formatted JSON
print type(userDataList) # dict
print type(inputData) # django.http.request.QueryDict
如何IM播种到服务器:
frm = $("#textCSVForm");
frm.submit(function(event) {
event.preventDefault()
$.ajax({
url: frm.attr('action'),
type: frm.attr('method'),
dataType: '',
data: {
json: json.data
},
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
})
.done(function(response) {
})
.fail(function() {})
.always(function() {
console.log(json.data); // logs the first formatted JSON
});
});
为什么你把它转向到一个列表? – Rishav
@Rishav你指的是''''.lists()'''?根据我的测试结果,输出有没有差异。但我没有特别的理由,为什么即时通讯使用''''.lists()'''我试过它,因为它有一个带有对象的数组。 – Kevin
你如何将数据发送到服务器? – Rishav