Forgive me if this is too broad a question, shout at me if so.
I'm retrieving data from a rest API in java. I then want to be able to search through the JSON data for a particular key-value pair. As far as I'm aware, a JSONObject from org.json is a good way of doing this. So far I have:
URL url = new URL("api string");
HttpURLConnection connnection = (HttpURLConnection)url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String input;
StringBuffer sb = new StringBuffer();
while ((input = br.readLine()) != null){
sb.append(input);
}
br.close();
returnedJSON = new JSONObject(sb.toString());
So fairly standard get request code.
Firstly, I can't tell if I need a JSONObject or JSONArray. Everything I've researched uses JSONObjects for writing to from an API, but I'll be retrieving JSON that is in the following form:
[ { x:y, a:b, foo:bar }, { x:y, a:b, foo:bar }, ... , ... ]
So there's multiple JSON "entries" if that makes sense, and I'd like to look through the entire JSON string to see if two pieces of data exist in the same record. Ex: Is the value of 'foo' the expected value for the record where the value of 'x' is 'y'?
I'm unclear on how to proceed here as it is the first time I've properly used JSON.