0

my app keeps returning "use JasonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $" when I try to register a user. I have gone through most of the questions relating to this but none has really helped me. below is the register process that initiates the connection to server.

 private void registerProcess( final String name,final String email,final String password){

    String tag_string_req = "req_register";
    //pDialog = new AlertDialog.Builder(getActivity());
    pDialog.setMessage("please wait");
    pDialog.show();

          Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(Constants.BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    RequestInterface requestInterface = retrofit.create(RequestInterface.class);

    User user = new User();
    user.setName(name);
    user.setEmail(email);
    user.setPassword(password);
    ServerRequest request = new ServerRequest();
    request.setOperation(Constants.REGISTER_OPERATION);
    request.setUser(user);
    Call<ServerResponse> response = requestInterface.operation(request);

    response.enqueue(new Callback<ServerResponse>() {
        private View view;

        public View getView() {
            return view;
        }

        @Override
        public void onResponse(Call<ServerResponse> call, retrofit2.Response<ServerResponse> response) {

            ServerResponse resp = response.body();

           // if(resp !=null)
            Toast.makeText(getApplicationContext(),response.message(), Toast.LENGTH_LONG).show();
            pDialog.dismiss();
        }


        @Override
        public void onFailure(Call<ServerResponse> call, Throwable t) {

           // progress.setVisibility(View.INVISIBLE);
            Log.d(Constants.TAG, "failed");
            Toast.makeText(getApplicationContext(), t.getLocalizedMessage(), Toast.LENGTH_LONG).show();
            pDialog.dismiss();


        }
    });
}
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Mani
  • 423
  • 1
  • 4
  • 13
  • you read this link : [link]https://stackoverflow.com/questions/39918814/use-jsonreader-setlenienttrue-to-accept-malformed-json-at-line-1-column-1-path – rizujikeda Jan 19 '19 at 14:12

1 Answers1

0

Please check what is the response at first. I think you are getting collection of json objects but you are trying to convert it to a single object. Make sure your response is a single json object or if you have json array response then tune up your code. Your code will actually work for single json object.

darkprince
  • 23
  • 5