-2

{ "status": "200", "errorMessage": "", "data": { "cleaner_tasks": { "2018-08-02": { "Mahindra & Mahindra": { "tasks": { "37": { "customer_name": "Neelam", "contact_no": "94625917" }, "38": { "customer_name": "Neelam", "contact_no": "9462591789" } }, "address": { "id": 1, "name": "Mahindra & Mahindra" } }, "2018-08-03": { "Mahindra & Mahindra": { "tasks": { "42": { "customer_name": "Neelam", "contact_no": "946259178" }, "43": { "customer_name": "Neelam", "contact_no": "9462591789" } }, "address": { "id": 1, "name": "Mahindra & Mahindra" } } } } }, "originalRequest": {}, "detailError": "" } }

Blockquote "here most off object key value comes dynamically " then how to crete a pojo class for retrofit

Nikita Jain
  • 35
  • 1
  • 7
  • Maybe you should correct question title to state that object KEY is dynamically changed, but not object value. @MichaelDodd you reference is not a duplicate of this question. – redlabrat Aug 01 '18 at 13:02
  • @redlabrat Noted. Question was just a JSON dump at the time with no context, so that's what I interpreted the question as. It's still unclear what OP is asking though IMO. – Michael Dodd Aug 01 '18 at 13:05
  • But as reference you should look at this question https://stackoverflow.com/questions/33758601/parse-dynamic-key-json-string-using-retrofit – redlabrat Aug 01 '18 at 13:05
  • @MichaelDodd the question is how to decode the JSON for the retrofit library. here the name of multiple objects comes dynamically. so I can't decode it. please help me – Nikita Jain Aug 02 '18 at 06:29

1 Answers1

0

Your JSON Formatting is not proper. cleaner_tasks should be jsonArray not JsonObject

but you can't Formate response then use as Follows.

 try {
        JSONObject object = new JSONObject(Data);
        JSONObject DataJsonObject = object.getJSONObject("data");
        JSONObject CleanerTaskJsonObject = DataJsonObject.getJSONObject("cleaner_tasks");

        Iterator<String> keys = CleanerTaskJsonObject.keys();
        while(keys.hasNext())
        {
          String aKey= keys.next();
            //all keys are here
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }
Divyesh
  • 66
  • 4