首先,我看到了“其他线程”,我认为其中没有一个使用PHP或javascript。
好吧,在我编码并添加了斜杠以逃脱JSON非法字符后,我有了这个数组:
"#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-12" "#Tahrir","2012-Oct-19" "#Tahrir","2012-Oct-19" "#Tahrir","2012-Oct-19"
想要将其更改为CSV或从此样本中找到一种与该图一起使用的方法:http://bl.ocks.org/3883245#data.tsv
提前致谢。
最佳答案
要将json数据转换为CSV,请尝试使用此http://jsfiddle.net/sturtevant/vUnF9/(不是我的代码)
function JSON2CSV(objArray) {
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
var str = '';
var line = '';
if ($("#labels").is(':checked')) {
var head = array[0];
if ($("#quote").is(':checked')) {
for (var index in array[0]) {
var value = index + "";
line += '"' + value.replace(/"/g, '""') + '",';
}
} else {
for (var index in array[0]) {
line += index + ',';
}
}
line = line.slice(0, -1);
str += line + '\r\n';
}
for (var i = 0; i < array.length; i++) {
var line = '';
if ($("#quote").is(':checked')) {
for (var index in array[i]) {
var value = array[i][index] + "";
line += '"' + value.replace(/"/g, '""') + '",';
}
} else {
for (var index in array[i]) {
line += array[i][index] + ',';
}
}
line = line.slice(0, -1);
str += line + '\r\n';
}
return str;
}