Gson gson = new Gson();
JsonReader reader = new JsonReader(new InputStreamReader(
new URL("http://api.mineplex.com/pc/player/abc?apiKey=1")
.openConnection().getInputStream()));
JsonElement json1 = gson.fromJson(reader, JsonElement.class);
JsonObject jsonObject1 = json1.getAsJsonObject();
該類崩潰,這樣的:GSON - JsonElement到JSONObject的轉換錯誤
Caused by: java.lang.IllegalStateException: Not a JSON Object: "<html>"
at com.google.gson.JsonElement.getAsJsonObject(JsonElement.java:90) ~[gson-2.2.4.jar:?]
爲什麼?
我在猜測,但嘗試更改「http」與「https」。 – Tobb
@Tobb https提供證書錯誤。 – MCCCS
@MCCCS你正在使用的鏈接正在重定向到實際頁面,儘管瀏覽器足以讓你做到從http重定向到https Java不會爲你做到這一點,你可以考慮使用https而不是http協議 – nafas