Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/04/2016, 04:19
Avatar de Luisda
Luisda
 
Fecha de Ingreso: octubre-2015
Ubicación: Villanueva de la Reina
Mensajes: 33
Antigüedad: 8 años, 6 meses
Puntos: 0
Pregunta Problema con gson

Buenas, tengo este trozo de código para recoger un array json devuelto de mi web service.

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);
                }
            }
        });
En la línea en la que he comentado que me da error, este es el error que me aparece.

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 $
Al probar el php en el navegador me devuelve esto:

Código HTML:
{"nombre_grupo":"LOL"}
No se a que puede ser debido el error. Un saludo y gracias de antemano.