übergeben Ich bin neu zu Retrofit, und nicht viel Ahnung, wie man diese Json mit Retrofit übergeben und in meiner App zu zeigen. Unten ist mein Json, MainActivity und Modellklasse. Aber wissen es wird eine Ausnahme ausgelöst "Außer begin_object aber find begin_array". Bitte helfen Sie mir.Wie JSON-Array mit Get-Methode in Retrofit android
[
{
"userId": 1,
"id": 1,
"title": "sunt",
"body": "sdfdsf"
},
{
"userId": 1,
"id": 2,
"title": "qui est esse",
"body": "jhmjk"
}]
MainActivity.java
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
ApiInterface apiService = retrofit.create(ApiInterface.class);
// ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);
Call<ModelClass> call = apiService.getLogin();
// Call<LoginResponse> call = apiService.loginWithCredentials(new LoginRequest(email_enter, md5pass));
call.enqueue(new Callback<ModelClass>() {
@Override
public void onResponse(Call<ModelClass> call, Response<ModelClass> response) {
Log.i("REGISTRATION --->", "Registered" + response);
}
@Override
public void onFailure(Call<ModelClass> call, Throwable t) {
Log.i("REGISTRATION --->", "Throwable" + t.toString());
// Intent i = new Intent(MainActivity.this,SecondActivity.class);
// startActivity(i);
}
});
}
ModelClass.java
public class ModelClass {
class Model{
public List<ObjectModel> getObjectmodel() {
return objectmodel;
}
public void setObjectmodel(List<ObjectModel> objectmodel) {
this.objectmodel = objectmodel;
}
List<ObjectModel> objectmodel;
}
class ObjectModel{
String userId;
String id;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
String title;
String body;
}
}
Mögliches Duplikat von [Wie JSON-Array im Körper in Retrofit übergeben werden] (http://stackoverflow.com/questions/41543318/how-to-pass-json-array-inside-body-in-retrofit) –
Can Sie sehen bitte diesen Link, mit JSON, wie man das http://stackoverflow.com/questions/42386604/login-user-retrofit-in-android-having-json-data-at-server –
übergeben Ich würde vorschlagen, zu übergeben die JSON-Daten im Körper als POST-Anfrage –