try{
JsonElement rawJson =
GsonUtils.JsonParser.parse(new InputStreamReader(
new URL("http://api.mineplex.com/pc/player/abc?apiKey=1")
.openConnection().getInputStream()));
}catch(JsonIOException | JsonSyntaxException | IOException e){
e.printStackTrace();
}
иGSON - Json Синтаксический Ошибка
public class GsonUtils
{
public static Gson gson = new Gson();
public static Gson prettyGson = new GsonBuilder().setPrettyPrinting()
.create();
public static JsonParser jsonParser = new JsonParser();
}
были классы, которые я использовал, чтобы получить JSON и разобрать его. Но когда я запускаю первый, он сообщает следующее StackTrace:
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 2 column 2
at com.google.gson.JsonParser.parse(JsonParser.java:65)
...
Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 2 column 2
at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1505)
at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1386)
at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:531)
at com.google.gson.stream.JsonReader.peek(JsonReader.java:414)
at com.google.gson.JsonParser.parse(JsonParser.java:60)
... 13 more
Это говорит мне, чтобы добавить JsonReader.setLenient(true)
в мой код, но мой код не использует JsonReader. Тогда как я могу добавить setLenient(true)
в свой код?
EDIT: Добавить ответ API (отформатированный):
{
"statusCode": 401,
"error": "Unauthorized",
"message": "Invalid API Key. To get an api key use the /api command in game"
}
Вы можете разместить текст ваш код получает от вызова API? –
@TimBiegeleisen сделано. – MCCCS
Возможный дубликат [gson throws MalformedJsonException] (http://stackoverflow.com/questions/11484353/gson-throws-malformedjsonexception) – Yazan