Develop/Android

[Android] json으로 데이터 받을 때 {} []

안다희 2019. 3. 5. 00:32
728x90


이렇게 끝이 {}이면

          Call<BookInfoWithBool> call = getNetworkManager().getBookApi().getListWithSearch(name);
call.enqueue(new Callback<BookInfoWithBool>() {
@Override
public void onResponse(Call<BookInfoWithBool> call, Response<BookInfoWithBool> response) {
BookInfoWithBool bookInfoWithBools = response.body();
if (response.isSuccessful()) {
BookInfo bookInfo = (BookInfo) bookInfoWithBools.getBookInfoList();
Boolean isExist = bookInfoWithBools.getIsExist();
Toast.makeText(RecommendDetailActivity.this, bookInfo.getBook_name() + " !!", Toast.LENGTH_SHORT).show();
// adapter = new RecyclerViewAdapter(getApplicationContext(), books, tagNames);
// recyclerView.setAdapter(adapter);

} else {
Toast.makeText(RecommendDetailActivity.this, "오류가 발생했습니다.", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<BookInfoWithBool> call, Throwable t) {
Toast.makeText(RecommendDetailActivity.this, "오류가 발생했습니다.", Toast.LENGTH_SHORT).show();
}
});

이렇게 받아도 되고,




이렇게 끝이 [] 이면


Call<List<Tag>> list = getNetworkManager().getBookApi().getTags(accessToken, idToken, refreshToken);
list.enqueue(new Callback<List<Tag>>() {
@Override
public void onResponse(Call<List<Tag>> call, Response<List<Tag>> response) {
List<Tag> tags = response.body();
tagNames.setAllTags(tags);
for (int i = 0; i < tagNames.getAllTags().size(); i++)
flowLayout.addTag(tagNames.getAllTags().get(i));

}

@Override
public void onFailure(Call<List<Tag>> call, Throwable t) {
Toast.makeText(MainActivity.this, "오류가 발생했습니다.", Toast.LENGTH_SHORT).show();
}
});

이렇게 <List<Tag>>로 가져오기1

출처: https://mingos-habitat.tistory.com/34 [밍고의서식지:티스토리]