{
"error": false,
"total": "20",
"total_page_no": 1,
"current_page_no": 1,
"data": [
{
"id": "4241",
"row_order": "0",
"name": "Shivaji Ponni Rice",
"tax_id": "1",
"slug": "Shivaji Ponni Rice",
"category_id": "52",
"subcategory_id": "196",
"indicator": "1",
"manufacturer": null,
"made_in": "Shivaji Ponni Rice",
"return_status": "1",
"cancelable_status": "1",
"till_status": "received",
"image": "http://www.pasumai.co.in/upload/default-image/default-image.png",
"other_images": [],
"description": "The best variety of rice is determined by its amount of usage. In that aspect, The Shivaji brand Matured variety of rice is highly recommended for every household. It is manufactured in the special unit and this variety is the rice matured between the months of august of one year to June of the succeeding year. It can be easily cooked and hence saves time. Perfect in shape, it is easy to digest and is suitable for any family possessing people of all age groups. Nevertheless, they produce a surplus since it is the matured variety of rice. Used by most of the families makes it the highest-selling variety of rice",
"status": "1",
"popular": "0",
"date_added": "2022-07-24 07:50:28",
"return_max_days": "0",
"tax": "0",
"price": "1500",
"tax_title": "GST",
"tax_percentage": "0",
"is_favorite": false,
"is_notify_me": false,
"variants": [
{
"id": "7477",
"product_id": "4241",
"type": "packet",
"measurement": "26",
"measurement_unit_id": "1",
"price": "1500",
"discounted_price": "1350",
"serve_for": "Available",
"stock": "20",
"stock_unit_id": "6",
"image": "upload/default-image/default-image.png",
"moq": "5",
"varient_status": "1",
"measurement_unit_name": "kg",
"stock_unit_name": "pcs",
"cart_count": "0",
"is_notify_me": false
}
]
},
{
"id": "4243",
"row_order": "0",
"name": "Semmoli Kichadi Ponni",
"tax_id": "1",
"slug": "Semmoli Kichadi Ponni",
"category_id": "52",
"subcategory_id": "196",
"indicator": "1",
"manufacturer": null,
"made_in": "Semmoli Kichadi Ponni",
"return_status": "1",
"cancelable_status": "1",
"till_status": "received",
"image": "http://www.pasumai.co.in/upload/default-image/default-image.png",
"other_images": [],
"description": "Nei Kichadi Ponni rice is best suited for all occasions. It is well known for premium quality, light weight, excellent aroma and taste. Its gluten free, does not contain any artificial flavours or preservatives",
"status": "1",
"popular": "0",
"date_added": "2022-07-24 07:50:28",
"return_max_days": "0",
"tax": "0",
"price": "1600",
"tax_title": "GST",
"tax_percentage": "0",
"is_favorite": false,
"is_notify_me": false,
"variants": [
{
"id": "7474",
"product_id": "4243",
"type": "packet",
"measurement": "26",
"measurement_unit_id": "1",
"price": "1600",
"discounted_price": "1420",
"serve_for": "Available",
"stock": "20",
"stock_unit_id": "6",
"image": "upload/default-image/default-image.png",
"moq": "5",
"varient_status": "1",
"measurement_unit_name": "kg",
"stock_unit_name": "pcs",
"cart_count": "0",
"is_notify_me": false
}
]
}
]
}
This is My Api Response..i am trying to get the response from retrofit and add the variants list into my room database .. for that i need to take all the variants from this response
I am trying to get all variants and put them in arraylist...how to do that using for loop...Is there any other way to get all variants inside data using Data Structure and Algorithms , means how it is
This is how i get my Api Response :
fun productlist() = viewModelScope.launch(Dispatchers.IO) {
productist.collectLatest {
when(it) {
Resource.Empty -> {
Log.e("catdata",""+"empty")
}
is Resource.Failure -> {
Log.e("catdata",""+"failure")
}
Resource.Loading -> {
}
is Resource.Success -> {
val response = it.value
productsDao.insertProducts(response.data)
}
}
}
}