I have a JSON string and I am trying to retrieve information from it. Json String looks like this.
{"information":{"device":{"id":0},"user":{"id":0},"data":[{"datum":{"id":"00GF001","history_id":"9992BH","name":"abc","marks":57,"class":"B","type":"Student"}},{"datum":{"id":"72BA9585","history_id":"78NAH2","name":"ndnmanet","marks":70,"class":"B","type":"Student"}},{"datum":{"id":"69AHH85","history_id":"NN00E3006","name":"kit","department":"EF003","class":"A","type":"Employee"}},{"datum":{"id":"09HL543","history_id":"34QWFTA","name":"jeff","department":"BH004","class":"A1","type":"Employee_HR"}}]}}
I am trying to access data JSONArray and respective Datum from it. I differentiated each datum as per type such as student, employee etc and push information in hashmap. I successfully did it in javascript but in Java I am struggle abit.
When I am trying to access JSONArray it throws exception
try {
JSONObject data = new JSONObject(dataInfo);
// Log.d(TAG, "CHECK"+data.toString());
if(current.getJSONArray("data").length() > 0) //exception here
Log.d(TAG, "Data"+ data.getJSONArray("signals").length()); //exception here too
for(int m = 0; m < data.length(); m++){
// for(int s = 0; s < data[m].ge)
}
} catch (JSONException j){
j.printStackTrace();
}
Any pointers to create hashmap respective type I have. Appreciated
0 comments:
Post a Comment