0

My code in local host is working good but in real host get this error.

"Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $"

When i add json to my code , it gives another error like this.

"com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $"

and this is my code :

public class ApiClient {


 private static final String BASE_URL = "http://aminkhataei.ir/android_login_api/";

  private static Retrofit retrofit = null;


  public static Retrofit getClient() {
    if (retrofit == null) {


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


      retrofit = new Retrofit.Builder()
        .baseUrl(BASE_URL)
        .addConverterFactory(GsonConverterFactory.create(gson))
        .build();
    }
    return retrofit;
  }

}

and my model :

  public class MyResponse {
  @SerializedName("uid")
  private String uid;
  @SerializedName("error")
  private boolean error;
  @SerializedName("msg")
  private String msg;

  public String getMsg() {
    return msg;
  }



  public String getUid() {
    return uid;
  }


  public boolean isError() {
    return error;
  }

  public void setError(boolean error) {
    this.error = error;
  } 
}

Can anyone help me ?

silent_27
  • 303
  • 3
  • 17
  • The problem seems to be with the response the live server is returning. Have a look at this [topic](https://stackoverflow.com/a/28418787/3809653). Your endpoint is returning "jj" instead of JsonObject you are expecting. – ArbenMaloku Dec 14 '18 at 14:25
  • jj is not important.just for test.how can do this in topic link?@ArbenMaloku – Android programmer Dec 14 '18 at 14:29
  • 1
    Have a look at this also [LINK](https://stackoverflow.com/a/40013869/3809653) – ArbenMaloku Dec 14 '18 at 14:32
  • I see this but I confused about structure in topic link@ArbenMaloku – Android programmer Dec 14 '18 at 14:39
  • Your server is sending you a string but you're accepting MyResponse. What do you not understand about this issue? – Zun Dec 14 '18 at 14:47
  • my respone like this: {"error":false,"uid":"5c13cc75a25978.01070617","user":{"name":"amin","created_at":"2018-12-14 18:59:57","updated_at":null,"email":"k@k.k"},"msg":"login !"} @ZUNJAE – Android programmer Dec 14 '18 at 15:34
  • _"My code in local host is working good"_ Okay fine. Did you test that API after hosting it in live server? Test it with Postman or any other REST API clients and confirm that it returns expected JSON data. I assume that API doesn't return proper JSON response after hosting. – Shashanth Dec 15 '18 at 07:11

0 Answers0