I have a json response below.
{"Table":[{"Count":1,"Result":"R"},{"Count":17,"Result":"Total Questions"},{"Count":16,"Result":"W"}]}
I have to parse the above json and display the question count as Right,Wrong,Not Answered and total Questions. I have tried as below. I am getting all the parameters as 17. Pls help me.
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
// try {
String url1 = "http://smarteach.com/questions/questions.svc/Learner_Qbank_Stats_Today/val1="
+ learnerid
+ "/val2="
+ courseid
+ "/val3="
+ session_id + "";
System.out.println("Stats from URL : " + url1);
ServiceHandler sh = new ServiceHandler();
jsonstring = sh.makeServiceCall(url1, ServiceHandler.GET);
System.out.println("Response: " + jsonstring);
if (jsonstring != null) {
try {
parent = new JSONObject(jsonstring);
contacts = parent.getJSONArray("Table");
for (int i = 0; i < contacts.length(); i++) {
parent = contacts.getJSONObject(i);
totalquestions = parent.getString("Count");
notanswered = parent.getString("Count");
correctanswered = parent.getString("Count");
wronganswered = parent.getString("Count");
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
Toast.makeText(getActivity(), "Please try after some time",
Toast.LENGTH_LONG).show();
}
return url1;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
p.dismiss();
tvbookmarkcount.setText(totalquestions);
tvquesunattempted.setText(notanswered);
tvcorrectanswered.setText(correctanswered);
tvwronganswered.setText(wronganswered);
}