我有一个这样的json(可能有一些语法错误,我确实提取并重写了一些私有数据)
"todo-items": [{
"id": 3511710,
"company-name": "company1",
"author" : "Jon Doe",
"tags": [{
"id": 10101,
"name": "2.Marketing Sales",
"color": "#f78234"
}],
"creation-date": 20160101
}, {
"id": 3511474,
"company-name": "company1",
"author" : "Jon Don",
"tags": [{
"id": 10101,
"name": "2.Marketing Sales",
"color": "#f78234"
}, {
"id": 10103,
"name": "4.Automotive",
"color": "#9b7cdb"
}],
"creation-date": 20160101
}, {
"id": 3511478,
"company-name": "company1",
"author" : "Peter Jon Doe",
"tags": [{
"id": 10101,
"name": "2.Marketing Sales",
"color": "#f78234"
}, {
"id": 9706,
"name": "3.sales",
"color": "#37ced0"
}, {
"id": 9562,
"name": "3.IT",
"color": "#37ced0"
}],
"creation-date": 20160101
}]
我使用 alasql 和 xlsx.core 库将其导出到 excel 文件。首先,我从原始 json 中删除 STATUS(由团队合作 API 提供),然后将 JSON 更改为 javascript 数组
$.ajax({
type: "GET",
url: requrl,
headers: {"Authorization": "BASIC " + window.btoa(key + ":xxx")},
success: function(data) {
delete data.STATUS;
//alert(data);
//console.log(data);
var arr = $.map(data, function(el) { return el });
//console.log(arr);
alasql("SELECT * INTO XLSX('test.xlsx',{headers:true}) FROM ? ",[arr]);
},
error: function(response) {
alert(response);
}
});
这很好用,我可以将我的 json 提取为 excel 文件,但是我在这个 json 中的标签对象有问题..当我将它更改为数组然后将它保存在 excel 中时,除了标签之外所有列都可以,我只看到 [object ][object] 你能帮我如何将这些标签也放入正确的数组中吗?最好是一个标签= excel中的一列