从服务器我收到JSON
这种格式的对象:
[ { "Id": 1, "defNo": "ME-2-17", "ReportDate": "2013-10-04T00:00:00", "Remarks": "" } ]
在循环中使用它我试图将它转换为一个数组,$.parseJSON(responseText
但转换后我仍然无法使用它,因为控制台说:
Uncaught TypeError: Object #<Object> has no method 'join'
功能齐全:
function exportToCsv() {
var formInfo = $("#requestSortForm").serialize();
$.post('../../REQUEST/GetSortedRequest', formInfo, function (responseText) {
data = $.parseJSON(responseText);
console.log($.parse(responseText));
var csvContent = "data:text/csv;charset=utf-8,";
data.forEach(function (infoArray, index) {
dataString = infoArray.join(",");
csvContent += index < infoArray.length ? dataString + "\n" : dataString;
});
var encodedUri = encodeURI(csvContent);
window.open(encodedUri);
});
}
我SO
从这里的答案中遵循这个例子