我的应用程序一直返回"使用JasonReader.setLenient(true)
接受第1行第1行路径格式错误的JSON
$"当我尝试注册用户时。我已经完成了与此相关的大部分问题,但没有一个真正帮助过我。下面是启动与服务器连接的注册过程。
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();
}
});
}
答案 0 :(得分:0)
请先查看回复是什么。我想你正在收集json对象,但是你试图将它转换为单个对象。确保您的响应是单个json对象,或者如果您有json数组响应,那么请调整您的代码。您的代码实际上适用于单个json对象。