I have used retrofit2. but I cannot catch the response because there is always showing zero data. How can I receive a response? I am using this code. (added debug code also for better understanding).
ApiClient.getApiClient().getPurchOrderEdit(map).enqueue(new Callback<Map<String, Map<String, List<Map<String, Object>>>>>() {
@Override
public void onResponse(Call<Map<String, Map<String, List<Map<String, Object>>>>> call, Response<Map<String, Map<String, List<Map<String, Object>>>>> response) {
System.out.println("test");
}
@Override
public void onFailure(Call<Map<String, Map<String, List<Map<String, Object>>>>> call, Throwable t) {
}
});
{
"TBLT_PURCHASE_ORDER_EDIT": {
"data": [
{
"column_id": "17705",
"po_id": "15872311254332020-04-18 23:32:05",
"db_id": "62",
"dbhouse_name": "Coca Cola DB House",
"depot_id": "3",
"dpo_name": "Tongi Depot",
"dist_emp_id": "140",
"first_name": "Coca cola DB",
"order_date": "2020-04-18",
"total_order": "1056",
"total_quantity": "24"
}
]
}
}
Make your API
call to return ApiResult
Your ApiResult
class:
public class ApiResult {
private String status;
private JsonElement result;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public JsonElement getResult() {
return result;
}
public void setResult(JsonElement result) {
this.result = result;
}
}
Use this code inside of Api onResponse
and replace YourDataObject
with your data class:
Type typeToken = new TypeToken<List<YourDataObject>>() {
}.getType();
List<YourDataObject> list = new ArrayList<>();
list = new Gson().fromJson(response.body().getResult().getAsJsonObject()
.getAsJsonArray("data"), typeToken);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.