【问题标题】:How can I import data from a CSV file into Adobe Air app?如何将 CSV 文件中的数据导入 Adob​​e Air 应用程序?
【发布时间】:2011-01-24 03:54:20
【问题描述】:

我打算在 flash builder 中编写一个应用程序,我希望能够将 CSV 数据导入 Adob​​e Air/flashbuilder 中的 SQLite 数据库。

我从来没有做过这样的事情,也不完全确定从哪里开始。 在重新插入数据之前,我想对数据进行一些操作。所以我真的需要知道我需要使用哪些步骤(类和函数)来将 CSV 文件中的数据解析为可以在 actionscript 中操作的数组?

【问题讨论】:

    标签: actionscript-3 sqlite csv import air


    【解决方案1】:

    我使用casalib 处理很多东西,包括加载。你可以使用标准的 as3 东西,但this 使它更容易。查看CasaLoader

    然后您可以使用一些字符串拆分来提取行/列

    sqlite 的东西非常简单。看看这个链接:http://ntt.cc/2008/07/08/sqlite-example-for-adobe-air-working-with-local-sql-databases-with-source-code.html

    你可以忽略 mxml 的东西

    【讨论】:

    • 还有一个名为 CSVlib 的开源 csv 解释动作脚本库
    【解决方案2】:

    [更新:我的回答假设 HTML/Javascript AIR,而不是 Flash/Actionscript。在 AS3 方面可能会有更好的答案...]

    您始终可以采用低级方法,通过 FileStream 读取它并自己编写 CSV 解析器。我怀疑你会找到一个预先存在的库来将任意 CSV 输入 SQLite,但也许我错了(我没看过)。

    您希望开始使用 FileStream 阅读器的基础知识类似于此示例代码,该代码在异步输入时读取一行。该示例从单独进程的 STDOUT 中读取,但应直接应用于 FileStream。

    this.process.addEventListener(air.ProgressEvent.STANDARD_OUTPUT_DATA, function(event) {
       // call into _stdoutHandler...
    });
    
    Foo.prototype._stdoutHandler = function() {
       var nBytes = this.process.standardOutput.bytesAvailable;
       var msg = this.process.standardOutput.readUTFBytes(nBytes);
       // The native process might send us partial lines, due to async IO.
       // Reconstruct the whole lines.
       this._sofar += msg;
       while (true) {
          var idx = this._sofar.indexOf("\n");
          if (idx < 0)
             break;
          if (idx > 0) { // skips blank lines
             var line = this._sofar.substring(0, idx);
             this._foundLine(line);
          }
          if (this._sofar.length > idx + 1) {
             this._sofar = this._sofar.substring(idx+1);
          } else {
             this._sofar = "";
          }
       }
       var lines = this._sofar.split(/\n/);
       if (lines.length > 1) {
          air.trace("programming error: we should have already handled all newlines");
       }
       this._sofar = lines[lines.length - 1];
    };
    
    Foo.prototype._foundLine = function() {
       // process a single line of input here...
    };
    

    【讨论】:

      猜你喜欢
      • 2011-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-17
      • 2020-07-04
      • 1970-01-01
      相关资源
      最近更新 更多