I want develop test application and for this I want use this API :
https://www.themealdb.com/api/json/v1/1/lookup.php?i=52772
In this API for show some info use many field, such as strIngredient1,strIngredient2,strIngredient3 and more to strIngredient15.
I want first check each of this items, and when not empty. then show this.
There are 15 items and I don't want check each of items!
I want check all of this items and each item not empty then show it!
How can I it? Is such a thing possible?
CodePudding user response:
I checked the response, In some case response may be like this due to bad code from backend developer and things will not be in our control.
I can understand your pain for these kind of scenario
We can do some hack to sort out your problem. Check out this code snippet
val meals = response.getJSONArray("meals")
val meal = meals.getJSONObject(0)
for(i in 1..20){
val gradient = meal.getString("strIngredient${i}")
if(!gradient.isNullOrBlank()){
println(gradient)
//Do whatever you want
}
}
I have just created a loop and the concat index with harcoded string that will make a required attribute name and you can get the data from that json object.
Hope it will hep you
Please upvote if its help you