0

I have a problem, getting

 Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

and I don't know how to solve it?

this is the API-end point

@FormUrlEncoded
    @Headers({"Accept: application/json"})
    @POST("/api/register")
    Call<User> register(@Field("name") String name,
                               @Field("email") String email,
                               @Field("national_id") String national_id,
                               @Field("phone") String phone,
                               @Field("password") String password,
                               @Field("password_confirmation") String password_confirmation);

and here is the call

 EndPoints Api = RetrofitCreation.getInstance();
            Call<User> call = Api.register(full_name, email, id, phone, password,password2);
            call.enqueue(new Callback<User>() {
                @Override
                public void onResponse(Call<User> call, Response<User> response) {
                    Log.e("register success",response.message().toString());
                    Toast.makeText(getApplicationContext(),
                            response.body().toString() +"",
                            Toast.LENGTH_LONG).show();
                }

                @Override
                public void onFailure(Call<User> call, Throwable t) {
                    Log.e("register fail", t.getMessage().toString());
                    Toast.makeText(getApplicationContext(),
                             t.getMessage()  ,
                            Toast.LENGTH_LONG).show();

                }
            });

the User class :

public class User {
public int id;
public String name;
public String national_id;
public String phone;
public int role_id;
public String email;

}

and finally, the response should be like this: response from post man

Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
Yasser
  • 1
  • 1

1 Answers1

0

You should use Json2Pojo to convert your JSON to a serializable or parcelable class. and don't forget to implement GSON library inside your app's Build.Gradle

Jayesh Nai
  • 361
  • 1
  • 4
  • 13