![](/img/trans.png)
[英]Error in parsing Json Object node while creating an issue of Jira using REST API of atlassian in Java
[英]JIRA Xray- Not a JSON Object error while making Rest API call to get Execution details
请帮助我尝试获取与 JIRA XRAY 中的执行相关的所有测试
我得到 java.lang.IllegalStateException: Not a JSON Object error at the step mentioned in the last below (element.getAsJsonObject();)
String urlString=baseServerURL+"/rest/raven/latest/api/testexec/"+executionCycleKey+"/test";
System.out.println(urlString);
HttpURLConnection con = getConnection(urlString, "GET");
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine.toString());
content.append(inputLine);
}
in.close();
con.disconnect();
Gson g = new Gson();
JsonElement element = g.fromJson(content.toString(), JsonElement.class);
JsonObject jsonObj = element.getAsJsonObject();
注意:inputLine 打印为 [{"id":100806,"status":"TODO","key":"ST_MABC-1234","rank":1}]
实际上,响应是一个包含 JSON 个对象的数组。 因此,您不能将其解析为 JSON object。您需要改用 JSONArray class。 例子:
String raw = "[{\"id\":100806,\"status\":\"TODO\",\"key\":\"ST_MABC-1234\",\"rank\":1} ]";
System.out.println(raw);
JSONArray arr = new JSONArray(raw);
System.out.println( ((JSONObject)(arr.get(0))).get("id"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.