在我的Json 2017中是年份,11是月份,下一个是日期
Well this is my json
{
"2017": {
"11": {
"8": {
"status": "P"
},
"10": {
"status": "A"
},
"24": {
"status": "A"
}
},
"12": {
"1": {
"status": "P"
},
"2": {
"status": "A"
}
}
}
}
这里我从Json获取值并存储在一些变量中
try {
JSONObject object = new JSONObject(response);
Iterator iterator = object.keys();
attendance_pojo pojo= new attendance_pojo();
while (iterator.hasNext()) {
String year = (String) iterator.next();
/*Log.d("year", year);*/
JSONObject obj = object.getJSONObject(year);
Iterator iterator2 = obj.keys();
while (iterator2.hasNext()) {
String month = (String) iterator2.next();
/*Log.d("month", month);*/
JSONObject ob = obj.getJSONObject(month);
Iterator iterator3 = ob.keys();
int datecntr=0;
while (iterator3.hasNext()) {
datecntr++;
String date = (String) iterator3.next();
pojo.setYear(year);
pojo.setMonth(month);
pojo.setDate(date);
JSONObject ob1 = ob.getJSONObject(date);
/*Log.d("16", date);*/
String status = ob1.getString("status");
if (status.equals("P"))
{
present++;
}
else
absent++;
/* Log.d("title", status);*/
}
pojo.setDatecounter(datecntr);
Log.d("counter",""+datecntr);
Log.d("kuqw",present+" "+absent);
pojo.setPresent(""+present);
pojo.setAbsent(""+absent);
present=0;
absent=0;
arrayList.add(pojo);
adapter.notifyDataSetChanged();
}
}
在这里,我从pojo中检索价值,以便我可以在一些文本视图中设置这些
attendance_pojo pojo= arrayList.get(position);
String months= pojo.getMonth();
Log.d("months",months);
months= checkmonth(months);
Log.d("datess",""+pojo.getDate());
month.setText(months+" "+pojo.getYear());
workdays.setText(""+pojo.getDatecounter());
But i am always getting 12 when I am getting Log of datess
12-04 15:27:25.220 2523-2523/rock.school_hub D/months: 12
12-04 15:27:25.226 2523-2523/rock.school_hub D/months: 12
12-04 15:27:25.229 2523-2523/rock.school_hub D/months: 12
12-04 15:27:25.236 2523-2523/rock.school_hub D/months: 12
根据我的json首先我应该得到11然后12,但在可变的月份,它总是显示12
答案 0 :(得分:0)
pojo.setDatecounter(datecntr);
Log.d("counter",""+datecntr);
Log.d("kuqw",present+" "+absent);
pojo.setPresent(""+present);
pojo.setAbsent(""+absent);
将此代码放在{}
中