Our team is currently working on developing a PhoneGap application. We are in the process of extracting data from a CSV file and storing it into a SQLite database using the File API in PhoneGap.
function readDataUrl(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as data URL");
console.log(evt.target.result);
};
reader.readAsDataURL(file);
}
function readAsText(file) {
console.log('in readAsText'+file);
var reader = new FileReader();
reader.onloadend = function(evt) {
ss=evt.target.result;
alert(ss);
console.log("Read as text");
console.log(evt.target.result);
};
reader.readAsText(file);
}
We have successfully obtained the data, but unfortunately, it is not in the appropriate format for inserting into the SQLite database. We require JSON formatted data for this purpose.
Below is an example of the desired JSON format:
[
{
"FOC":1,
"price":0,
"customerid":"ARU005",
"lineamount":0,
"items":"W.D.M.W HERBAL 250Mx24",
"tdate":"2015-4-7",
"qty":8,
"orderId":"Himansu16:23:20020",
"umo":"CTN",
"descriptions":"100mg",
"bookorder":"ABCARU0052320"
}
]
[
{
"TOTALAMOUNT":1000,
"DISCOUNT":1,
"NETAMOUNT ":900,
"VAT":0,
"GROSSAMOUNT ":900,
"BOOKORDER":"ABCARUOO7451",
"CUSTOMERID":"ARU007",
"TODAYDATE":"2015-4-7"
}
]
We are seeking guidance on how to convert the extracted data into JSON format from the CSV file. Any assistance would be greatly appreciated.