I want to parse a json array and get its individual elements in android. I have my json file in asset folder. This is type of my json:
{
"name":"hello",
"data":[1,2,3,4]
}
I want to get the elements of "data" key such as "1","2","3",& "4" so that I can add it to an array list.The file name is gaitData.json. I tried this method but its not able to read individual elements of array "data". Please help!!
InputStream is = MainActivity.this.getAssets().open("gaitdata.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json=new String(buffer,"UTF-8");
JSONObject object=new JSONObject(json);
JSONArray hip_min=object.getJSONArray("hip_min");
After this step I iterate the hip_min array using for loop but that does not work either.