I'm trying to extract the first element in key and the value from the following json data. However, most examples I've seen have been using org.json which seems to be outdated? What would be the best way to do this with the following json file?
"data": [
{
"key": [
"01",
"2015"
],
"values": [
"2231439"
]
},
{
"key": [
"03",
"2015"
],
"values": [
"354164"
]
},
{
"key": [
"04",
"2015"
],
"values": [
"283712"
]
}
]
}
This is how I get the json response and store it in a String which gives the json data from above.
HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
httpConnection.setRequestMethod("POST");
httpConnection.setDoOutput(true);
OutputStream os = httpConnection.getOutputStream();
os.write(jsonText.getBytes());
os.flush();
os.close();
int responseCode = httpConnection.getResponseCode();
System.out.println(responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader br = new BufferedReader(new InputStreamReader(httpConnection.getInputStream()));
String input;
StringBuffer response = new StringBuffer();
while ((input = br.readLine()) != null) {
response.append(input);
}
br.close();
String responseJson = response.toString();