-1

sort this below array according to 'future_time_status' column. future_time_status can be dynamic.

"data": [
    {
        "o_id": "8729",
        "business_id": "221",
        "userId": "1667",
        "order_name": "adi test",
        "category": "0",
        "subcategory": null,
        "order_desc": "",
        "amt": "190.00",
        "order_ph": " 9511297468",
        "odate": "2019-11-25",
        "address": "fff Mega Center, Hadapsar, Pune, Maharashtra, Pune",
        "paymode": "Cash On Delivery",
        "status": "Pending",
        "pickupdeliverytype": "delivery",
        "branch": null,
        "discountvoucher": "",
        "popupflag": "0",
        "created_at": "2019-11-25 19:30:00",
        "discountamt": "0.0",
        "TimeSlot": "",
        "CST": "2.1",
        "GST": "2.1",
        "PACK_CHRGS": "5",
        "DELI_CHRGS": "5",
        "referralamt": "",
        "tax_paid": "9.2",
        "note": "",
        "latitude": "18.5035",
        "longitude": "73.9256",
        "total_order_saving": "0",
        "deal_id": "0",
        "future_status": "0",
        "future_date": "2019-11-25",
        "future_time_status": "07:00 PM to 11:00 PM",
        "version_name": "1.1.63",
        "voucher_cashback_status": "0",
        "wallet_amount": "0.02",
        "profit_loss_amt": "50.00",
        "business_margin_flag": "0",
        "business_margin": "0",
        "order_remark": "",
        "online_payment_orderId": "0",
        "rider_name": null
    },
    {
        "o_id": "8728",
        "business_id": "111",
        "userId": "1667",
        "order_name": "adi test",
        "category": "0",
        "subcategory": null,
        "order_desc": "",
        "amt": "176.00",
        "order_ph": " 9511297468",
        "odate": "2019-11-25",
        "address": "fff Mega Center, Hadapsar, Pune, Maharashtra, Pune",
        "paymode": "Cash On Delivery",
        "status": "Pending",
        "pickupdeliverytype": "delivery",
        "branch": null,
        "discountvoucher": "",
        "popupflag": "0",
        "created_at": "2019-11-25 12:59:26",
        "discountamt": "0.0",
        "TimeSlot": "",
        "CST": "0",
        "GST": "0",
        "PACK_CHRGS": "5",
        "DELI_CHRGS": "17",
        "referralamt": "",
        "tax_paid": "5",
        "note": "",
        "latitude": "18.5035",
        "longitude": "73.9256",
        "total_order_saving": "0",
        "deal_id": "0",
        "future_status": "0",
        "future_date": "0000-00-00",
        "future_time_status": "",
        "version_name": "1.1.63",
        "voucher_cashback_status": "0",
        "wallet_amount": "0.02",
        "profit_loss_amt": "22.00",
        "business_margin_flag": "0",
        "business_margin": "0",
        "order_remark": "",
        "online_payment_orderId": "0",
        "rider_name": null
    },
    {
        "o_id": "8727",
        "business_id": "111",
        "userId": "1667",
        "order_name": "adi test",
        "category": "0",
        "subcategory": null,
        "order_desc": "",
        "amt": "132.00",
        "order_ph": " 9511297468",
        "odate": "2019-11-25",
        "address": "fff Mega Center, Hadapsar, Pune, Maharashtra, Pune",
        "paymode": "Cash On Delivery",
        "status": "Pending",
        "pickupdeliverytype": "delivery",
        "branch": null,
        "discountvoucher": "",
        "popupflag": "0",
        "created_at": "2019-11-25 12:59:10",
        "discountamt": "0.0",
        "TimeSlot": "",
        "CST": "0",
        "GST": "0",
        "PACK_CHRGS": "5",
        "DELI_CHRGS": "17",
        "referralamt": "",
        "tax_paid": "5",
        "note": "",
        "latitude": "18.5035",
        "longitude": "73.9256",
        "total_order_saving": "0",
        "deal_id": "0",
        "future_status": "0",
        "future_date": "0000-00-00",
        "future_time_status": "",
        "version_name": "1.1.63",
        "voucher_cashback_status": "0",
        "wallet_amount": "0.03",
        "profit_loss_amt": "22.00",
        "business_margin_flag": "0",
        "business_margin": "0",
        "order_remark": "",
        "online_payment_orderId": "0",
        "rider_name": null
    },
    {
        "o_id": "8726",
        "business_id": "256",
        "userId": "1667",
        "order_name": "adi test",
        "category": "0",
        "subcategory": null,
        "order_desc": "",
        "amt": "100.00",
        "order_ph": " 9511297468",
        "odate": "2019-11-25",
        "address": "fff Mega Center, Hadapsar, Pune, Maharashtra, Pune",
        "paymode": "Cash On Delivery",
        "status": "Pending",
        "pickupdeliverytype": "delivery",
        "branch": null,
        "discountvoucher": "",
        "popupflag": "0",
        "created_at": "2019-11-25 19:30:00",
        "discountamt": "0.0",
        "TimeSlot": "",
        "CST": "0",
        "GST": "0",
        "PACK_CHRGS": "3",
        "DELI_CHRGS": "5",
        "referralamt": "",
        "tax_paid": "3",
        "note": "",
        "latitude": "18.5035",
        "longitude": "73.9256",
        "total_order_saving": "0",
        "deal_id": "43166",
        "future_status": "0",
        "future_date": "2019-11-25",
        "future_time_status": "07:00 PM to 11:00 PM",
        "version_name": "1.1.63",
        "voucher_cashback_status": "0",
        "wallet_amount": "0.04",
        "profit_loss_amt": "8.00",
        "business_margin_flag": "0",
        "business_margin": "0",
        "order_remark": "",
        "online_payment_orderId": "0",
        "rider_name": null
    }
]
Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77
mahesh
  • 1
  • 1
  • Possible duplicate of [Sort ArrayList of custom Objects by property](https://stackoverflow.com/questions/2784514/sort-arraylist-of-custom-objects-by-property) – ADM Nov 25 '19 at 09:13
  • First parse the json into a List then sort it with a `Comparator` as shown in above link .. – ADM Nov 25 '19 at 09:14
  • Deserialise your `JSON` payload using `Gson` ([Array of JSON Object to Java POJO](https://stackoverflow.com/questions/55248523/array-of-json-object-to-java-pojo)) and use @ADM link to sort `List` after that. – Michał Ziober Nov 25 '19 at 09:23

1 Answers1

0

If you are writing in Kotlin - just parse the JSON array to a List and then just call:

array.sortBy { item -> 
    item.futureTimeStatus
}
orimen
  • 571
  • 4
  • 11