Adobe AIR的:SQLite的转换的结果[对象对象]为String? [英] Adobe Air: convert sqlite's result [object Object] to String?

查看:113
本文介绍了Adobe AIR的:SQLite的转换的结果[对象对象]为String?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前要做的检索sqlite的文本。我看到,请你一定要来正确的数据,但内容量,而另一方面,似乎是在一个不正确的格式。我已经尝试了一些转换:

I am currently trying to do retrieve text from sqlite. I see that the amount of data requested do come correctly, but content, on the other hand, seems to be in an incorrect format. I've tried some conversion:

var data:Array = sqls.getResult().data;

var stData:String = String(data[0]);

Alert.show(stData); // <--- displays "[object Object]"

字符串转换似乎并没有做我想做的。我只是想从SQLite数据库的文字。我怎么能转换[对象对象],以正确的字符串在这种情​​况下?

String conversion does not seem to do what I want. I simply want the text from the sqlite database. How can I convert the [object Object] to the correct string in this case?

推荐答案

无论返回哪些行(带(出))指定的列,除非将SQLStatement的itemClass属性的定义,它总是会返回一个匿名对象。这实质上是如何远程工作与AMF。

Irrespective of what rows are returned (with(out)) specifying columns, unless the itemClass property of the SQLStatement is defined, it will always return an anonymous object. This is essentially how remoting works with AMF.

有两件事情可以做(取决于项目的复杂程度):

There are two things you can do (depending on the complexity of your project):

  1. 指定一个SQLStatement.itemClass - 这将定义与放大器;这样就把返回公共访问的结果(无论是VAR或获取/套)具有相同的名称作为列名。
  2. 如果保留为匿名 - 列名连接到您遍历就像你如果它被定义的对象的对象

超基本的例子:

Super basic example:

//SQL table schema
CREATE TABLE accounts (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  num INTEGER NOT NULL,
  name TEXT NOT NULL,
  last_update DATE
);

//Define an Account class:
public class Account {
    public var id:int;
    public var num:int;
    public var name:String;
    public var last_update:Date;
}

//A statement to execute to get all accounts returned as an array of "Account"
var statement:SQLStatement = new SQLStatement();
    statement.sqlConnection = myConn;
    statement.itemClass = Account;
    statement.text = 'SELECT * FROM accounts';
    statement.addEventListener(SQLEvent.RESULT, onResults);
    statement.execute();

 protected function onResults(event:SQLEvent):void
 {
      var statement:SQLStatement = SQLStatement(event.currentTarget);
      var results:SQLResult = statement.getResult();
      for each (var account:Account in results)
      {
          //do something useful like populate a model, grid, etc...
      }
 }


 //Anonymous objects would iterate much the same way -when an item class isn't defined
 protected function onResults(event:SQLEvent):void
 {
      var statement:SQLStatement = SQLStatement(event.currentTarget);
      var results:SQLResult = statement.getResult();
      for each (var account:Object in results)
      {
          //our 'Object' will have properties: id, num, name, last_update
          //do something useful like populate a model, grid, etc...
      }
 }

这篇关于Adobe AIR的:SQLite的转换的结果[对象对象]为String?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆