Código HTML:
Call call = client.newCall(request); call.enqueue(new okhttp3.Callback() { @Override public void onFailure(Call call, IOException e) { Log.e("TAG", "(onFailure) The request was not successful"); } @Override public void onResponse(Call call, Response response) throws IOException { try { if (response.isSuccessful()) { result = response.body().string(); Gson gson = new Gson(); String jsonOutput = result; //Select one //EN ESTA LÍNEA ES DONDE ME DA EL ERROR grupo = gson.fromJson(jsonOutput,Grupos.class); //Select all /*Type listType = new TypeToken<List<Grupos>>(){}.getType(); posts = (List<Grupos>) gson.fromJson(jsonOutput, listType);*/ } else { Log.v("TAG", "(onResponse) Was not successful"); } } catch (IOException e) { Log.e("TAG", "Exception caught: ", e); } } });
Código HTML:
FATAL EXCEPTION: OkHttp Dispatcher Process: com.example.jaime.pruebaapi, PID: 13449 com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
Código HTML:
{"nombre_grupo":"LOL"}