Im transfering data from a json file to an arrayList in order to filter those values. The problem is that i want to access to especific data of the json object. In this case i want to create an arrayList with the "value" numbers.
JSON file:
{
"I": [
{
"value": 2984,
"time": 1563550463
},
{
"value": 2984,
"time": 1563550465
},
{
"value": 2984,
"time": 1563550467
},
{
"value": 2984,
"time": 1563550469
},
...
Main class:
public class Main {
public static void main(String[] args) {
JSONObject obj = JSONUtils.getJSONObjectFromFile("/15s_60bpm_ecg_data.json");
String[] names = JSONObject.getNames(obj);
for(String string : names) {
//System.out.println(string);
//System.out.println(string + ":" + obj.get(string));
}
JSONArray jsonArray = obj.getJSONArray("II");
CargarArray(jsonArray);
for(int i = 0; i < jsonArray.length(); i++) {
//System.out.println(jsonArray.get(i));
}
}
public static void CargarArray(JSONArray jsonArray){
ArrayList<Integer> Lista = new ArrayList<>();
for(int i = 0; i < jsonArray.length(); i++){
try {
JSONObject json = jsonArray.getJSONObject(i);
Lista.add(json.getInt("value"));
for (int j = 0; j < Lista.size(); j++) {
Lista.get(j);
System.out.println(j);
}
}
catch (JSONException e) {
e.printStackTrace();
}
}
}
}
What i expect is to get an arrayList with all the "values"