[英]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.