У меня есть API, в котором параметры являются электронной почтой и паролем. Пароль должен быть зашифрован. Поскольку я использую retrofit в первый раз. Пройдя мой json онлайн, я создал класс модели now.But все еще сталкивается с ошибкой «Except Begin_object, но найден строка в строке 1 столбец 1». Я уже много часов пробовал на этом Пожалуйста Помоги мне.Войти с помощью модификации в android с данными json на сервере дает ошибку «Except Begin_object, но найден строка в строке 1 столбец 1»
Мой JSON является:
{
"result": {
"userId": 2,
"userName": "Ram",
"emailId": "[email protected]",
"phoneNumber": "1234567890",
"eula": 0,
"status": 0,
"role": 1,
"password": "4ba007ae1e4045c3c784fdgefg",
"creationDate": {
"date": "2016-12-21 05:45:17.000000",
"timezone_type": 3,
"timezone": "India"
},
"apiKey": "dsadaskjfhckjhdsfhlksdfsdf4542",
"lastModified": {
"date": "2017-02-2 03:25:04.000000",
"timezone_type": 3,
"timezone": "India"
},
"language": "English",
"familyId": "",
"productId": "",
"partId": "",
"company": "ABC",
"address": "xyz",
"groupIds": "6",
"notes": null,
"logo": null,
"createdBy": 1056,
"passwordHint": "v$",
"isArchived": 0,
"UnSuccessLoginCount": 0,
"isLocked": 0,
"lockedTime": {
"date": "2012:09:02 00:00:00.000000",
"timezone_type": 3,
"timezone": "India"
},
"lockable": 0
},
"message": true
}
MainActivity.java
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email_enter = email.getText().toString();
String pass_enter = password.getText().toString();
String md5pass = md5(pass_enter);
LoginRequest loginRequest = new LoginRequest();
loginRequest.setEmail(email_enter);
loginRequest.setPassword(md5pass);
singinRequest(loginRequest);
}
});
private void singinRequest(LoginRequest loginRequest) {
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
ApiInterface apiService = retrofit.create(ApiInterface.class);
Call<LoginResponse.result> call = apiService.getLogin(loginRequest);
// Call<LoginResponse> call = apiService.loginWithCredentials(new LoginRequest(email_enter, md5pass));
call.enqueue(new Callback<LoginResponse.result>() {
@Override
public void onResponse(Call<LoginResponse.result> call, Response<LoginResponse.result> response) {
Log.i("REGISTRATION --->", "Registered" + response.body());
Intent i = new Intent(MainActivity.this,SecondActivity.class);
startActivity(i);
}
@Override
public void onFailure(Call<LoginResponse.result> call, Throwable t) {
Log.i("REGISTRATION --->", "Throwable" + t.toString());
}
});
}
LoginResponse.java
@SerializedName("result")
@Expose
private Result result;
@SerializedName("message")
@Expose
private Boolean message;
public Result getResult() {
return result;
}
public void setResult(Result result) {
this.result = result;
}
public Boolean getMessage() {
return message;
}
public void setMessage(Boolean message) {
this.message = message;
}
ApiInterface.java
@POST("/rest/DoLogin")
Call<LoginResponse.result> getLogin(@Body LoginRequest loginRequest);
Какая ошибка? Можете ли вы опубликовать журнал? –
Эта ошибка «Методы обслуживания не могут вернуть пустоту». возникают, если я использую public void в ApiInterface.java и «no annotation found» error, если я использую приведенный выше код –
Посмотрите [здесь] (http://stackoverflow.com/questions/36703737/simple-login-form -with-retrofit), [здесь] (http://stackoverflow.com/questions/33514454/need-help-for-retrofit-login-example) и [здесь] (https://inducesmile.com/android/android -user-login-and-registration-with-retrofit-php-mysql-and-slim-framework /), пропуская серверную часть –