【问题标题】:JasonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $ errorJasonReader.setLenient(true) 在第 1 行第 1 列路径 $ 错误处接受格式错误的 JSON
【发布时间】:2018-05-17 11:52:16
【问题描述】:

当我尝试注册用户时,我的应用程序不断返回“使用 JasonReader.setLenient(true) 接受格式错误的 JSON 在第 1 列第 1 路径 $”。我已经解决了与此相关的大部分问题,但没有一个真正帮助我。下面是启动与服务器连接的注册过程。

 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();


        }
    });
}

【问题讨论】:

标签: java android json web-services


【解决方案1】:

请先检查一下响应是什么。我认为您正在收集 json 对象,但您正试图将其转换为单个对象。确保您的响应是单个 json 对象,或者如果您有 json 数组响应,则调整您的代码。您的代码实际上适用于单个 json 对象。

【讨论】:

  • 请问我该怎么做
猜你喜欢
  • 2017-06-03
  • 2017-02-16
  • 1970-01-01
  • 2018-08-25
  • 1970-01-01
  • 1970-01-01
  • 2018-06-24
  • 2020-02-08
  • 2018-08-24
相关资源
最近更新 更多