ORMLite 返回 JSON 的顺序?

Order of JSON returned by ORMLite?

我是 Web 服务的新手,正在尝试使用 ORMLite 查询一些表,它不支持连接语句,所以我使用的是原始查询。我想知道是否有一种方法可以指定 JSON 的返回方式。我现在拥有的是:

Dao<CodesModel,String> CodesDao = DaoManager.createDao(connectionSource, CodesModel.class);

    GenericRawResults<String[]> rawResults =
      CodesDao.queryRaw(
        "select r.CodeA, s.SubCodeA, r.CodeB, s.SubCodeB " + 
        "from CodesTable r JOIN SubCodesTable s ON s.CodeA = r.CodeA " + 
        "where SubCodeB = '" + b_sub + "' AND r.CodeB = '" + b_code + "'");

并且结果以 String[] 的形式返回,并且似乎总是按照

的顺序

[代码A, 子代码A, 代码B, 子代码B]

但我只在本地对此进行了测试,无法在文档中找到确定返回数组中变量顺序的因素。

结果以这种方式排序,因为这是您在 select 语句中指定的顺序。如果您希望结果以不同的方式排序,请在查询中重新排序。

如果有人在使用 "select *" 时想知道列名,您也可以在 rawResults 对象上使用 "getColumnNames()",它们将始终按照结果的顺序排列。例子

    //The result is returned as a GenericRawResults object
    List<String[]> results = rawResults.getResults();
    String[] columns = rawResults.getColumnNames();

    JSONObject obj = new JSONObject();

    if(results.size()>0)
    {
        obj.put(columns[0], results.get(0)[0]);
        obj.put(columns[1], results.get(0)[1]);
        obj.put(columns[2], results.get(0)[2]);
        obj.put(columns[3], results.get(0)[3]);
    }