-1

The following link is my format of JSON file. https://api.myjson.com/bins/13wm1h

I have googled and found many examples for this https://api.myjson.com/bins/gopg5

But I need it for the first link in my question.

Can anyone help me solving this issue or guide me to a similar question with a similar JSON format?

takiuddin93
  • 41
  • 2
  • 11
  • Not sure what you asking for. You want someone to help your create model classes which can result into the required JSON format(1st link)? – Ahmad Raza Feb 13 '18 at 19:43
  • Possible duplicate of [How to parse JSON in Android](https://stackoverflow.com/questions/9605913/how-to-parse-json-in-android) – tar Feb 13 '18 at 19:57
  • @AhmadRaza yes, i am sorry i was not sure what to do. I just have this json file. I need to decode it in my .java class and display them in a list view chronologically. – takiuddin93 Feb 13 '18 at 20:07
  • 1
    @tar my json format isn't the same as that..i have looked into that question. – takiuddin93 Feb 13 '18 at 20:12

2 Answers2

0

Sounds like what you are needing is a deserializer. https://guides.codepath.com/android/converting-json-to-models

Zach Metcalf
  • 21
  • 1
  • 4
  • your link is a solution for my second link..i have done that..but that is not what i need. I need to parse this one https://api.myjson.com/bins/13wm1h – takiuddin93 Feb 13 '18 at 20:17
  • it would work for both objects. define your Model's as something like `List data`; define DayObjectsMap as `Map DayObjectsMap` and `DayObjects as `Map DayObjects` – Zach Metcalf Feb 20 '18 at 17:56
0

This will get you started.

public class JSON {

    public static void main(String[] args) throws JSONException {


        String jsonData = "";
        BufferedReader br = null;
        try {
            String line;
            br = new BufferedReader(new FileReader("PATH_TO_JSON/example.json"));
            while ((line = br.readLine()) != null) {
                jsonData += line + "\n";
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null)
                    br.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }


        JSONObject object = new JSONObject(jsonData);
        JSONObject saturday = object.getJSONObject("data").getJSONObject("Saturday");
        JSONObject sunday = object.getJSONObject("data").getJSONObject("Sunday");
        JSONObject monday = object.getJSONObject("data").getJSONObject("Monday");

        System.out.println(saturday);
        System.out.println(sunday);
        System.out.println(monday);

        System.out.println(saturday.getString("08:00:00"));

    }

}

This will print out.

{"08:00:00":"E","17:00:00":"H","05:00:00":"B","07:00:00":"C","12:00:00":"F","20:30:00":"I","02:00:00":"A","22:00:00":"K","07:30:00":"D","15:00:00":"G","23:00:00":"L","21:00:00":"J"}

{"08:00:00":"Q","17:00:00":"T","05:00:00":"N","07:00:00":"O","12:00:00":"R","20:30:00":"U","02:00:00":"M","22:00:00":"W","07:30:00":"P","15:00:00":"S","23:00:00":"X","21:00:00":"V"}

{"08:00:00":"C","17:00:00":"F","05:00:00":"Z","07:00:00":"A","12:00:00":"D","20:30:00":"G","02:00:00":"Y","22:00:00":"I","07:30:00":"B","15:00:00":"E","23:00:00":"J","21:00:00":"H"}

E

letsCode
  • 2,774
  • 1
  • 13
  • 37