I'm trying to use retro fit with some json but can't see what's wrong with my json string, i keep getting the same error.
I'm expecting an list of word objects but ive missed something? Any ideas?
retrofit.converter.ConversionException: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
JSON:
{
"words": [
{
"id": "1",
"word": "submarine",
"word_syllables": "sub-mar-ine",
"picture": "none.jpg",
"picture_dir": "",
"soundfile": "",
"user_id": "1",
"created": "2015-04-08 16:32:07",
"modified": "0000-00-00 00:00:00"
},
{
"id": "2",
"word": "computer",
"word_syllables": "com-pute-r",
"picture": "computer.jpg",
"picture_dir": "",
"soundfile": "",
"user_id": "0",
"created": "2015-04-08 16:32:07",
"modified": "0000-00-00 00:00:00"
}
]
}
Retrofit Android code:
private void requestData(){
RestAdapter adapter=new RestAdapter.Builder()
.setEndpoint(ENDPOINT)
.build();
WordsAPI api=adapter.create(WordsAPI.class);
api.getRestWordFeed(new Callback<List<Word>>(){
@Override
public void failure(RetrofitError arg0) {
// TODO Auto-generated method stub
Log.v("error",arg0.getMessage());
}
@Override
public void success(List arg0, Response arg1) {
// TODO Auto-generated method stub
wordList=arg0;
printList();
}
});
}
API interface:
package com.example.testretrofitlib;
import java.util.List;
import retrofit.Callback;
import retrofit.http.GET;
public interface WordsAPI {
@GET("/rest_words/index.json")
public void getRestWordFeed(Callback<List<Word>> response);
}