簡體   English   中英

將JSON轉換為放置在SD卡中的CSV文件

[英]Convert JSON to CSV file placed into Sdcard

我們正在開發Phonegap app.We需要SqLite放入DB數據SDCard 。我們做了sqLite數據轉換成JSON String.now我們發送到SDCard 。采用此鏈接中的PhoneGap文件API

我們將這個json數據編碼到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);
}

但是當我們以我的手機打開它的CSV文件時,它是JSON格式

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

但是我們需要CSV文件中的表格格式。

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

此行數據發送到CSV文件

writer.write(JSONData);

請指導我。

  1. 請創建一個模型類Item。
  2. 創建具有相同項目類類型的數組列表。
  3. 從項目類對象中的數據庫中獲取所有數據,並將其放入數組列表中。
  4. 粘貼json之后,在SD卡中創建一個csv文件。

5將所有陣列列表數據寫入csv文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM