Je suis nouveau pour mettre à jour et obtenir cette erreur (BEGIN_ARRAY attendue mais BEGIN_OBJECT à la ligne 1 colonne 2) sur HTTP simple demande get. Voici le code.Help me..`RETROFIT 2 Attendu BEGIN_ARRAY mais BEGIN_OBJECT était à la ligne 1 colonne 2
Activité principale
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.pagination_list);
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("https://www.googleapis.com/books/v1/")
.addConverterFactory(GsonConverterFactory.create());
Retrofit retrofit = builder.build();
String apiKey = getResources().getString(R.string.API_KEY);
GitHubClient client = retrofit.create(GitHubClient.class);
Call<List<Volumes>> call = client.reposForUser(apiKey);
call.enqueue(new Callback<List<Volumes>>() {
@Override
public void onResponse(Call<List<Volumes>> call, Response<List<Volumes>> response) {
List<Volumes> repos = response.body();
int responseCode = response.code();
Log.v("Volumeinfo", "onResponse: "+ responseCode);
listView.setAdapter(new GitHubRepoAdapter(MainActivity.this, repos));
}
@Override
public void onFailure(Call<List<Volumes>> call, Throwable t) {
Log.v("Volumeinfo", "onResponse: "+ t.getMessage());
Toast.makeText(MainActivity.this, t.getMessage()+"error :(", Toast.LENGTH_LONG).show();
}
});
}
Interface
{
@GET("volumes?q=Android+intitle")
Call<List<Volumes>> reposForUser(@Query("key")String ApiKey);
}
public class Volumes {
@SerializedName("title")
@Expose
private String title;
public String getTitle() {
return title;
}
}
Adaptateur
private Context context;
private List<Volumes> values;
public GitHubRepoAdapter(Context context, List<Volumes> values) {
super(context, R.layout.list_item_pagination, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.list_item_pagination, parent, false);
}
TextView textView = (TextView) row.findViewById(R.id.list_item_pagination_text);
Volumes item = values.get(position);
String message = item.getTitle();
textView.setText(message);
return row;
}
}
Json
{
"kind": "books#volumes",
"totalItems": 3395,
"items": [
{
"kind": "books#volume",
"id": "1igDDgAAQBAJ",
"etag": "oS4LeBsRcfg",
"selfLink": "https://www.googleapis.com/books/v1/volumes/1igDDgAAQBAJ",
"volumeInfo": {
"title": "Android Programming",
"subtitle": "The Big Nerd Ranch Guide",
"authors": [
"Bill Phillips",
"Chris Stewart",
"Kristin Marsicano"
],
"publisher": "Pearson Technology Group",
"publishedDate": "2017-01-30",
"description": "This is the eBook of the printed book and may not include
",
"industryIdentifiers": [
{
"type": "ISBN_13",
"identifier": "9780134706078"
},
{
"type": "ISBN_10",
"identifier": "0134706072"
}
],
"readingModes": {
"text": true,
"image": true
},
"pageCount": 624,
"printType": "BOOK",
"categories": [
"Computers"
],
"maturityRating": "NOT_MATURE",
"allowAnonLogging": true,
"contentVersion": "1.1.1.0.preview.3",
"panelizationSummary": {
"containsEpubBubbles": false,
"containsImageBubbles": false
},
"imageLinks": {
"smallThumbnail": "http://books.google.com/books/content?
id=1igDDgAAQBAJ&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api",
"thumbnail": "http://books.google.com/books/content?
id=1igDDgAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api"
},
"language": "en",
"previewLink": "http://books.google.com/books?
complet JSON https://www.googleapis.com/books/v1/volumes?q=Android+intitle
Presque cherché partout ..help sera vraiment apprécié