如何从中获取 _id :
"hits": {
"total": 2,
"max_score": 1.9808292,
"hits": [
{
"_index": "posts",
"_type": "post",
"_id": "5G3BC3gKV1NaSLvfPw44",
"_score": 1.9808292,
"_source": {
"title": "LoremIpsum"
}
}
]
}
使用此回调:
Call<HitsObject> call = searchAPI.search(headerMap, "AND", searchString);
call.enqueue(new Callback<HitsObject>() {
@Override
public void onResponse(Call<HitsObject> call, Response<HitsObject> response) {
HitsList hitsList = new HitsList();
String jsonResponse = "";
try {
if (response.isSuccessful()) {
hitsList = response.body().getHits();
} else {
jsonResponse = response.errorBody().string();
}
for (int i = 0; i < hitsList.getPostIndex().size(); i++) {
blog_list.add(hitsList.getPostIndex().get(i).getPost());
}
blogRecyclerAdapter.notifyDataSetChanged();
删除了onfailure和catch回调以缩短代码 提前感谢!