-1

I want to parse the 'audience' array.

 String data =   {
  "meta":{
    "requests":31454,
    "timestamp":1456706180,
    "status":200,
    "message":"Request successful",
    "method_id":1129,
    "method":{

    }
  },
  "data":[
    {
      "id":3681,
      "employer":"Google",
      "date":"2016-01-05",
      "day":"January",
      "start_time":"17:00",
      "end_time":"19:00",
      "description":"Info session to discuss options at Google for majors outside of Computer Science.",
      "website":"http:\/\/www.google.com\/careers\/students",
      "building":{
        "code":"FED",
        "name":"Federation Hall",
        "room":"Main Hall",
        "latitude":43.4732,
        "longitude":-80.5485,
        "map_url":"https:\/\/uwaterloo.ca\/map\/FED?basemap=D#map=17\/43.4732\/-80.5485"
      },
      "audience":[
        "ENG - Computer",
        "ENG - Electrical",
        "ENG - Mechatronics",
        "ENG - Software",
        "ENG - System Design",
        "MATH - Combinatorics & Optimization",
        "MATH - Computer Science",
        "MATH - Pure Mathematics"
      ],
      "link":"http:\/\/www.ceca.uwaterloo.ca\/students\/hiresessions_details.php?id=3681"
    } 
      }

I started with

 JSONObject obj = new JSONObject(data);
        JSONArray data2 = new JSONArray(obj);

But I am unsure how to get the "audience" data now? I tried to create another array from data2, but that gave an error, so I really am not sure how to proceed?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
DilllyBar
  • 59
  • 1
  • 7
  • Explain the downvote. Thats just stupid – DilllyBar Nov 09 '16 at 09:34
  • Downvotes arent stupid. Leaving out maybe an error that you are getting would be. And so would not reading [How to parse JSON in Android](http://stackoverflow.com/questions/9605913/how-to-parse-json-in-android) – OneCricketeer Nov 09 '16 at 09:43

1 Answers1

0

Good start with

JSONObject obj = new JSONObject(data);

Then, that's an object that you need to get the "data" array out of, not make a new array from that object.

JSONArray data = obj.getJsonArray("data");

Once you have an array, you can iterate over that with a regular for loop, up to i < data.length().

As you iterate that array, you have more JSON objects that you need to get

JSONObject inner = data.getJSONObject(i);

And those have the audience array.

JSONArray audience = inner.getJSONArray("audience");

Feel free to use this site and Gson or Jackson libraries to aid your parsing efforts

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245