Пример ответа
"hints": [
{
"food": {
"foodId": "food_amqspy5ap567v6bun60usbgsaor7",
"label": "Nuts",
"knownAs": "nuts",
"nutrients": {
"ENERC_KCAL": 594,
"PROCNT": 17.3,
"FAT": 51.45,
"CHOCDF": 25.35,
"FIBTG": 9
},
"category": "Generic foods",
"categoryLabel": "food",
"image": "https://www.edamam.com/food-img/e29/e2985d3585a6950c276e204ba7ba9b2e.jpg"
},
protected void onPostExecute(String s) {
try {
JSONObject jsonObject = new JSONObject(s);
JSONArray jsonArray = jsonObject.getJSONArray("hints");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject hintObject = jsonArray.getJSONObject(i);
JSONObject foodObject = hintObject.getJSONObject("food");
String label = foodObject.getString("label");
String image = foodObject.getString("image");
JSONObject nutrientsObject = foodObject.getJSONObject("nutrients");
String enercKcal = nutrientsObject.getString("ENERC_KCAL");
String procnt = nutrientsObject.getString("PROCNT");
String fat = nutrientsObject.getString("FAT");
String chocdf = nutrientsObject.getString("CHOCDF");
String fibtg = nutrientsObject.getString("FIBTG");
FoodModels model = new FoodModels();
model.setName(label);
model.setImg(image);
model.setKcal(enercKcal);
model.setProcent(procnt);
model.setFat(fat);
model.setChocdf(chocdf);
model.setFidtg(fibtg);
foodModelsList.add(model);
}
} catch (JSONException e) {
e.printStackTrace();
}
PutDataIntoRecyclerView(foodModelsList);
}