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