Хочу сделать авторизацию. Выдает Error: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

login.java


public class login extends AppCompatActivity {
    TextView email, pass;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        email = (TextView) findViewById(R.id.log);
        pass = (TextView) findViewById(R.id.pass);
    }

    public void reg1(View view) {
        Intent intent = new Intent(login.this, register.class);
        startActivity(intent);
    }

    public void vhodakk(View view) {
        if (email.getText().toString().length() == 0) {
            email.setError("Введите Email");
        }

        if (pass.getText().toString().length() == 0) {
            pass.setError("Ведите пароль");
        } else {

            Gson gson = new GsonBuilder()
                    .setLenient()
                    .create();

           HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient.Builder client = new OkHttpClient.Builder()
                .addInterceptor(interceptor);

            Retrofit retrofit = new Retrofit.Builder()
                    .baseUrl("http://mskko2021.mad.hakta.pro/api/user")
                    .client(client.build())
                    .addConverterFactory(GsonConverterFactory.create(gson))
                    .build();


            JSONPlaceHolderApi api = retrofit.create(JSONPlaceHolderApi.class);
            // LoginRequest loginRequest = new LoginRequest();
            try {
                JSONObject paramObject = new JSONObject();
                paramObject.put("email", email.toString());
                paramObject.put("password", pass.toString());

                //loginRequest.email = email.toString();
                //loginRequest.password = pass.toString();

                Call<LoginResponse> call = api.getUser(paramObject.toString());
                call.enqueue(new Callback<LoginResponse>() {
                    @Override
                    public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
                        LoginResponse loginResponse = response.body();

                        if (loginResponse != null) {
                            Log.d("authLog", loginResponse.data.token);
                            // Intent intent = new Intent(login.this, main.class);
                            //startActivity(intent);

                        }


                    }

                    @Override
                    public void onFailure(Call<LoginResponse> call, Throwable t) {
                        Log.d("authLog", "Error: " + t.getMessage());

                    }

                });

            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    }
} ```


----------


JSON.java

```public interface JSONPlaceHolderApi {
    
    @Headers("Content-Type: application/json")
    @POST("login")
    Call<LoginResponse> getUser(@Body String body);

}```


----------
LiginResponse.java

```public class LoginResponse {

    @Nullable
    @SerializedName("data")
    public Data data;

    public class Data {

        @Nullable
        @SerializedName("token")
        public String token;

    }

    @Nullable
    @SerializedName("error")
    public String error;

    @Nullable
    @SerializedName("system")
    public System system;

    public class System {

        @Nullable
        @SerializedName("time")
        public double time;

    }
}```


----------
LoginRequest.java

public class LoginRequest {
    public LoginRequest() {
        this.email = email;
        this.password = password;
    }

    @SerializedName("email")
    String email;

    @SerializedName("password")
    String password;

Ответы (0 шт):