mardi 7 avril 2015

convert json to csv file placed into Sdcard

We are developing Phonegap app.We need SqLite Db data placed into SDCard.We did sqLite Data convert into JSON String.now we send to SDCard.Using this link File API in PhoneGap


We code this json data placed into SDCard



document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
//alert("seeeeee1");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
alert("seeeeee2");
fileSystem.root.getFile("forTEST.csv", {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
alert("seeeeee3");
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
alert("set");
writer.onwriteend = function(evt) {
};
writer.write(JSONData);
}


But when we open it's CSV file in my mobile.it's JSON format



[
{
"items": "BODYLINESUPER",
"descriptions": "100mg",
"umo": "CTN",
"qty": 7,
"price": 1093.55,
"lineamount": 7654.85,
"customerid": "ARU007",
"tdate": "2015-4-7",
"orderId": "Himansu15",
}
]


but We need Table format in CSV file.like



items descriptions umo qty price lineamount customerid tdate orderId
BODYLINESUPER 100mg CTN 7 1093.55 7654.85 ARU007 2015-4-7 Himansu15


this line Data send to CSV file



writer.write(JSONData);


Please guide me.


Aucun commentaire:

Enregistrer un commentaire