我正在尝试运行示例 java 程序来检索拉力赛中的前 5 个缺陷。我收到以下错误:
查询前 5 个最高优先级的未修复缺陷... 线程“主”com.google.gson.JsonSyntaxException 中的异常:com.google.gson.stream.MalformedJsonException:第 1 行第 21 列的预期 EOF 在 com.google.gson.JsonParser.parse(JsonParser.java:65) 在 com.google.gson.JsonParser.parse(JsonParser.java:45) 在 com.rallydev.rest.response.Response.(Response.java:25) 在 com.rallydev.rest.response.QueryResponse.(QueryResponse.java:16) 在 com.rallydev.rest.RallyRestApi.query(RallyRestApi.java:179) 在 QueryExample.main(QueryExample.java:36) 引起:com.google.gson.stream.MalformedJsonException:第 1 行第 21 列的预期 EOF 在 com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1298) 在 com.google.gson.stream.JsonReader.peek(JsonReader.java:390) 在 com.google.gson.JsonParser.parse(JsonParser.java:60) ... 5 更多
源代码如下:
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.request.QueryRequest;
import com.rallydev.rest.response.QueryResponse;
import com.rallydev.rest.util.Fetch;
import com.rallydev.rest.util.QueryFilter;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class QueryExample {
public static void main(String[] args) throws URISyntaxException, IOException {
//Create and configure a new instance of RallyRestApi
RallyRestApi restApi = new RallyRestApi(new URI("https://rally1.rallydev.com/#/4608446320ud"), "stephen5@netapp.com", "password");
restApi.setApplicationName("QueryExample");
try {
System.out.println("Querying for top 5 highest priority unfixed defects...");
QueryRequest defects = new QueryRequest("defect");
defects.setFetch(new Fetch("FormattedID", "Name", "State", "Priority"));
defects.setQueryFilter(new QueryFilter("State", "<", "Fixed"));
defects.setOrder("Priority ASC,FormattedID ASC");
//Return up to 5, 1 per page
defects.setPageSize(1);
defects.setLimit(5);
QueryResponse queryResponse = restApi.query(defects);
if (queryResponse.wasSuccessful()) {
System.out.println(String.format("\nTotal results: %d", queryResponse.getTotalResultCount()));
System.out.println("Top 5:");
for (JsonElement result : queryResponse.getResults()) {
JsonObject defect = result.getAsJsonObject();
System.out.println(String.format("\t%s - %s: Priority=%s, State=%s",
defect.get("FormattedID").getAsString(),
defect.get("Name").getAsString(),
defect.get("Priority").getAsString(),
defect.get("State").getAsString()));
}
} else {
System.err.println("The following errors occurred: ");
for (String err : queryResponse.getErrors()) {
System.err.println("\t" + err);
}
}
} finally {
//Release resources
restApi.close();
}
}
}
非常感谢任何有关导致此问题的帮助!