Search code examples
androidjsonretrofit2

how to get the data in this Api using retrofit in android


I got a null pointer exception while fetching these details

                 "order": 8,
                "month": "November",
                "amount": "450",
                "given": "450",
                "date": "12-Sep-2018".

Can someone tell me how to get the data in this type of JSON format using retrofit?

 {
        "status": 1,
        "msg": "Data found Successfully..!",
        "data": [
            {
                "subject": "Tution Fee",
                "sequence": 1,
                "months": {
                    "7": {
                        "order": 7,
                        "month": "October",
                        "amount": "450",
                        "given": "450",
                        "date": "12-Sep-2018",
                        "status": "Paid"
                    },
                    "8": {
                        "order": 8,
                        "month": "November",
                        "amount": "450",
                        "given": "450",
                        "date": "12-Sep-2018",
                        "status": "Paid"
                    },
                    "9": {
                        "order": 9,
                        "month": "December",
                        "amount": "200",
                        "given": null,
                        "status": "Due"
                    },
                    "10": {
                        "order": 10,
                        "month": "January",
                        "amount": "450",
                        "given": null,
                        "status": "Due"
                    },
                    "11": {
                        "order": 11,
                        "month": "February",
                        "amount": "450",
                        "given": null,
                        "status": "Due"
                    },
                    "12": {
                        "order": 12,
                        "month": "March",
                        "amount": "450",
                        "given": null,
                        "status": "Due"
                    }
                }
            },
            {
                "subject": "Transport Fee",
                "sequence": 2,
                "months": {
                    "7": {
                        "order": 7,
                        "month": "October",
                        "amount": "400.00",
                        "given": "400",
                        "date": "12-Sep-2018",
                        "status": "Paid"
                    },
                    "8": {
                        "order": 8,
                        "month": "November",
                        "amount": "400",
                        "given": "400",
                        "date": "12-Sep-2018",
                        "status": "Paid"
                    },
                    "9": {
                        "order": 9,
                        "month": "December",
                        "amount": "400",
                        "given": null,
                        "status": "Due"
                    },
                    "10": {
                        "order": 10,
                        "month": "January",
                        "amount": "400.00",
                        "given": null,
                        "status": "Due"
                    },
                    "11": {
                        "order": 11,
                        "month": "February",
                        "amount": "400.00",
                        "given": null,
                        "status": "Due"
                    },
                    "12": {
                        "order": 12,
                        "month": "March",
                        "amount": "400.00",
                        "given": null,
                        "status": "Due"
                    }
                }
            },
            {
                "subject": "Other Fee",
                "sequence": 3,
                "months": {
                    "1": {
                        "order": 1,
                        "month": "Back_dues",
                        "amount": 300,
                        "given": 0,
                        "status": "Due"
                    }
                }
            },
            {
                "subject": "computer_test22",
                "sequence": 4,
                "months": {
                    "1": {
                        "order": 1,
                        "month": "April",
                        "amount": "100",
                        "given": "0",
                        "status": "Due"
                    },
                    "2": {
                        "order": 2,
                        "month": "May",
                        "amount": "100",
                        "given": "0",
                        "status": "Due"
                    },
                    "3": {
                        "order": 3,
                        "month": "June",
                        "amount": "100",
                        "given": "0",
                        "status": "Due"
                    },
                    "4": {
                        "order": 4,
                        "month": "July ",
                        "amount": "100",
                        "given": "0",
                        "status": "Due"
                    },
                    "5": {
                        "order": 5,
                        "month": "August",
                        "amount": "100",
                        "given": "0",
                        "status": "Due"
                    },
                    "6": {
                        "order": 6,
                        "month": "September",
                        "amount": "100",
                        "given": "0",
                        "status": "Due"
                    },
                    "7": {
                        "order": 7,
                        "month": "October",
                        "amount": "100",
                        "given": "0",
                        "status": "Due"
                    },
                    "8": {
                        "order": 8,
                        "month": "November",
                        "amount": "100",
                        "given": "0",
                        "status": "Due"
                    },
                    "9": {
                        "order": 9,
                        "month": "December",
                        "amount": "100",
                        "given": "0",
                        "status": "Due"
                    },
                    "10": {
                        "order": 10,
                        "month": "January",
                        "amount": "100",
                        "given": "0",
                        "status": "Due"
                    },
                    "11": {
                        "order": 11,
                        "month": "February",
                        "amount": "100",
                        "given": "0",
                        "status": "Due"
                    },
                    "12": {
                        "order": 12,
                        "month": "March",
                        "amount": "100",
                        "given": "0",
                        "status": "Due"
                    }
                }
            }
        ],
        "current_status": {
            "subject": "Current Month-(July)",
            "amount": 8750,
            "given": 1700,
            "remain": 7050,
            "status": "due"
        }
    }

Solution

  • you can do this from you model object that you are using for retrofit response model. like hashMap<String,jsonObject>(), or you can use class object for "jsonObject" replacement