So I am using the MPandroid chart dependency to plot the graph on an android app. For this I am adding data to an ArrayList of class Entry of the graph. I am adding the data manually for now but I want to parse a the data from a json file and add it to graph. can anyone tell me how can I read individual data elements of Json array to add to graph.
This is the code I am using to read the json file.I have the file in my asset folder.
try {
InputStream is=getAssets().open("gaitdata.json");
int size=is.available();
byte[] buffer=new byte[size];
is.read(buffer);
is.close();
json=new String(buffer,"UTF-8");
JSONArray jsonArray=new JSONArray(json);
for(int i=0;i<jsonArray.length();i++){
JSONObject obj=jsonArray.getJSONObject(i);
if(obj.getString("name").equals("kinematics")){
hipvalue.add(obj.getString("hip_min"));
}
}
Also this is the json file I want to read.
{
"name":"kinematics",
"hip_min":[1.2,5.67,2.34,6.8]
}
Also I want the float value but since it is not working so I have used obj.getString() to get the "hip_min" value for json.
And Lastly this is how I add data manually to Array list.
ArrayList<Entry> entries=new ArrayList<>();
entries.add(new Entry(0,19.85f));