I have this valid JSON string and it can have many rows. I have just posted a fragment.
var jsonStr = ["{\"r1\":768,\"r2\":1,\"r3\":\"System Admin\",\"r4\":\"2013-06-08T05:51:23.000Z\",\"r5\":1,\"r6\":\"System Admin\",\"r7\":false}"]
I need to send the above to CSV. Follwed this Post
CSV gets exported with r1,r2,r3.. but i dont need the keys r1, r3 , r3.. etc . I just need the values . I followed the same example.
Any pointers ?
var jsonStr = ["{\"r1\":768,\"r2\":1,\"r3\":\"System Admin\",\"r4\":\"2013-06-08T05:51:23.000Z\",\"r5\":1,\"r6\":\"System Admin\",\"r7\":false}"]
DownloadJSON2CSV(jsonStr);
function DownloadJSON2CSV(objArray) {
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
var str = '';
for (var i = 0; i < array.length; i++) {
var line = '';
var tmp = 0;
var nx = 1;
for (var index in array[i]) {
line += array[i][index];
if (tmp == 0) {
nx = array[0][3];
}
tmp++;
}
line.slice(0, line.Length - 1);
str += line + '\r\n';
}
window.open("data:text/csv;charset=utf-8," + escape(str))
}
Here's the Fiddle : http://jsfiddle.net/ufjUY/