【问题标题】:Convert JSON to CSV file placed into Sdcard将 JSON 转换为 CSV 文件放入 Sdcard
【发布时间】:2015-04-07 13:25:29
【问题描述】:

我们正在开发Phonegap 应用程序。我们需要将SqLite Db 数据放入SDCard。我们将sqLite 数据转换为JSON String。现在我们发送到SDCard。使用此链接@987654321 @

我们将这个 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",
  }
]

但是我们需要CSVfile.like中的表格格式

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);

请指导我。

【问题讨论】:

    标签: javascript android sqlite cordova android-sdcard


    【解决方案1】:
    1. 请创建一个模型类Item。
    2. 创建具有相同项类类型的数组列表。
    3. 从项目类对象中的数据库中获取所有数据并放入数组列表中。
    4. 解析 json 后在 sd 卡中创建一个 csv 文件。

    5 将所有数组列表数据写入csv文件。

    【讨论】:

    • 在这种情况下,Parse 服务器没有互联网。我们需要将 SqLite Db 数据以表格格式放入 CSV 文件中。请帮助我
    • 请指导我不知道创建模型类项目。我们只有 SqlLite 数据转换成 JSON 对象请指导我
    • 我们按照您所说的将数据写入 csv 文件。它工作得很好。现在我们有两个数组 List 现在我们需要将数据发布 csv 文件,如 List1 到 Sheet1 和 List2 到 Sheet2 请指导我
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-31
    • 1970-01-01
    • 2023-03-03
    • 2021-03-31
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多