2

我正在使用以下代码来获取测试集 ID。但它没有给出任何结果

QueryRequest testsetRequest = new QueryRequest("Test Set");
testsetRequest.setFetch(new Fetch("FormattedID","Name"));
testsetRequest.setQueryFilter(new QueryFilter("TestSet.Name", "=", "TestSetName"));
QueryResponse testSetQueryResponse = restApi.query(testsetRequest);
System.out.println(String.format("\nTestSet:%d",testSetQueryResponse.getTotalResultCount()));
StringTestSetref=testSetQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").toString();
System.out.println(TestSetref);
4

1 回答 1

2

您可能在查询中遇到错误。像这样的代码应该可以工作。如果查询出现问题,else 子句还将帮助您诊断遇到的错误。

QueryRequest testsetRequest = new QueryRequest("TestSet"); //no spaces
testsetRequest.setFetch(new Fetch("FormattedID","Name"));     

//No need to specify type again 
testsetRequest.setQueryFilter(new QueryFilter("Name", "=", "TestSetName")); 
QueryResponse testSetQueryResponse = restApi.query(testsetRequest);

if(testSetQueryResponse.wasSuccessful()) {
    for (JsonElement result : testSetQueryResponse.getResults()) {
        //handle results
    }
} else {
    //See what error occurred
    for (String err : testSetQueryResponse.getErrors()) {
        System.err.println("\t" + err);
    }
}
于 2012-10-10T15:23:28.190 回答