請幫助我正在嘗試獲取與 JIRA XRAY 中的執行相關的所有測驗
我在下面最后提到的步驟中收到 java.lang.IllegalStateException: Not a JSON Object 錯誤(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}]
uj5u.com熱心網友回復:
實際上,回應是一個 JSON 物件陣列。因此,您不能將其決議為 JSON 物件。您需要改用 JSONArray 類。例子:
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"));
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/432484.html
標籤:爪哇 json 硒网络驱动程序 jira-rest-api 吉拉X射线
上一篇:反序列化集合時杰克遜JSON窒息
下一篇:使用可能回傳不同資料的JSON
