J'obtiens cette erreur:Modèle de base de données ORMLite vers GSON via une erreur d'adaptateur de retrofit; java.lang.IllegalStateException
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
Je suis en train de créer à partir de ce rappel JSON http://pastebin.com/bC8s3bUf, directement à partir de cette URL.
Le modèle de données est représenté en tant que modèle de base de données ORMLite. Création JSON via GSON crée manuellement cette chaîne JSON: http://pastebin.com/bC8s3bUf
Base de données Modèle
@DatabaseField(id = true, index = true, canBeNull = true, columnName = ID)
String id;
@DatabaseField(columnName = TITLE)
String title;
@DatabaseField(columnName = DESCRIPTION)
String description;
@DatabaseField(columnName = DATE)
String date;
@DatabaseField(columnName = IMAGE)
String image;
@DatabaseField(columnName = IS_SAVED_TO_CLOUD)
boolean isSavedToCloud;
@DatabaseField(columnName = DATE_EDITED)
String dateEdited;
@DatabaseField(columnName = IS_DELETED)
boolean isDeleted;
public FoodLog() {
id = UUID.randomUUID().toString();
isSavedToCloud = false;
isDeleted = false;
}
@Override
public int describeContents() {
return 0;
}
public FoodLog(Parcel in) {
this.id = in.readString();
this.title = in.readString();
this.description = in.readString();
this.date = in.readString();
this.image = in.readString();
this.isSavedToCloud = (in.readByte() != 0);
this.dateEdited = in.readString();
this.isDeleted = (in.readByte() != 0);
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeString(id);
out.writeString(title);
out.writeString(description);
out.writeString(date);
out.writeString(image);
out.writeByte((byte) (isSavedToCloud ? 1 : 0));
out.writeString(dateEdited);
out.writeByte((byte) (isDeleted ? 1 : 0));
}
public static final Parcelable.Creator<FoodLog> CREATOR = new Parcelable.Creator<FoodLog>(){
public FoodLog createFromParcel(Parcel in){
return new FoodLog(in);
}
public FoodLog[] newArray(int size){
return new FoodLog[size];
}
};
Interface
public interface FoodLogInterface {
@GET(IntentConstants.API_URL)
Call<List<FoodLog>> getFoodLog();
@POST(IntentConstants.API_URL)
Call<List<FoodLog>> postFoodLog(@Body List<FoodLog> foodLog);}
Obtenir des données depuis l'URL
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://pastebin.com/bC8s3bUf")
.addConverterFactory(GsonConverterFactory.create())
.build();
FoodLogInterface service = retrofit.create(FoodLogInterface.class);
Call<List<FoodLog>> call = service.getFoodLog();
call.enqueue(new Callback<List<FoodLog>>() {
@Override
public void onResponse(Response<List<FoodLog>> response, Retrofit retrofit) {
Log.d("CallBack", " response is " + response);
}
@Override
public void onFailure(Throwable t) {
Log.d("CallBack", " Throwable is " +t);
}
});
}
Peut-être essayer http://pastebin.com/raw/bC8s3bUf comme URL. Ce qui pointe directement vers le .json et non vers la page. Pourrait aider. – Templum
Cela a fonctionné, j'ai eu réponse! Merci beaucoup! – robigroza
Ensuite, je l'affiche comme une réponse. Serait bien si vous pouviez accepter cela alors – Templum