我从服务器响应中得到两个json数组。我可以在模型类中设置它,但是我不知道我在哪里做错了,因为这些值在列表中不可见。请检查我的代码并告诉我,我的错。
我在活动课程中的方法
private void pastappointments() {
final String requestBody = "'{\"UtcTimeOffset\":\"330\",\"DocId\":\"1079\"}'";
Log.e(TAG, "Login :: " + requestBody);
NetworkManager.getInstance(this).makeNetworkRequestForJSON(1, Request.Method.POST, Common.BASE_URL + "/PostDoctorGetDoctorSchedule", null, requestBody
, null,
new NetworkResponseListenerJSONObject() {
@Override
public void onDataReceived(int requestCode, Object data) {
Log.e(TAG, "requestCode :: " + requestCode);
Log.e(TAG, "data :: " + data);
Log.e(TAG, "Response : " + data.toString());
try {
JSONObject jsonObject = new JSONObject(data.toString());
JSONObject ResponseJsonObject1 = jsonObject.getJSONObject("Response");
int ResponseCode = ResponseJsonObject1.getInt("ResponseCode");
String ResponseText = ResponseJsonObject1.getString("ResponseText");
if (ResponseCode == 1) {
JSONArray arrDetail = jsonObject.getJSONArray("Detail");
for(int i = 0; i < arrDetail.length(); i++) {
JSONObject jSlot = arrDetail.getJSONObject(i);
PostDoctorGetDoctorSchedule slotInfo = new PostDoctorGetDoctorSchedule();
slotInfo.BlockId = jSlot.getString("BlockId");
slotInfo.DateOfSlot = jSlot.getString("DateOfSlot");
slotInfo.fkScheduledId = jSlot.getInt("fkScheduledId");
slotInfo.fkTimeId= jSlot.getString("fkTimeId");
slotInfo.AvailableTimeSlots = new ArrayList<>();
JSONArray arrAvailableTimeSlots = jsonObject.getJSONArray("AvailableTimeSlots");
for(int j = 0; j < arrAvailableTimeSlots.length(); j++) {
JSONObject jAvailableTimeSlot = arrAvailableTimeSlots.getJSONObject(j);
AvailableTimeSlots availableTimeSlot = new AvailableTimeSlots();
availableTimeSlot.timeOfSlot = jAvailableTimeSlot.getString("TimeOfSlot");
slotInfo.AvailableTimeSlots.add(availableTimeSlot);
}
// then GetBlockedTimings
slotInfo.GetBlockedTimings = new ArrayList<>();
JSONArray arrGetBlockedTimings = jsonObject.getJSONArray("GetBlockedTimings");
for(int k = 0; k < arrGetBlockedTimings.length(); k++) {
JSONObject jGetBlockedTiming = arrAvailableTimeSlots.getJSONObject(k);
GetBlockedTimings getBlockedTiming = new GetBlockedTimings();
getBlockedTiming.blockId = jGetBlockedTiming.getInt("fkTimeId_block");
slotInfo.GetBlockedTimings.add(getBlockedTiming);
}
slotInfos.add(slotInfo);
}
}
pastAppointmentsAdapter = new PastAppointmentAdapter(Mainactivity3.this, slotInfos);
rv_get_doctor_schedule.setAdapter(pastAppointmentsAdapter);
}
catch (JSONException e)
{
e.printStackTrace();
}
// pastAppointmentsAdapter.notifyDataSetChanged(); }
@Override
public void onDataFailed(int requestCode, VolleyError error) {
Log.e(TAG, "requestCode :: " + requestCode);
Log.e(TAG, "data :: " + error);
String json = null;
NetworkResponse response = error.networkResponse;
if (response != null && response.data != null) {
switch (response.statusCode) {
case 400:
json = new String(response.data);
json = trimMessage(json, "error_description");
if (json != null) displayMessage(json);
break;
}
//Additional cases
}
}
});
}
My Adapter class code
public class PastAppointmentAdapter extends RecyclerView.Adapter<PastAppointmentsViewHolder> {
private static final String TAG = "UpcomingAppoinmentsListAdapter";
private ArrayList<AvailableTimeSlots> pastAppointmentlist;
private ArrayList<GetBlockedTimings> getBlockedTimings;
private List<GetBlockedTimings> getblocklist;
private ArrayList<PostDoctorGetDoctorSchedule> PostDoctorGetDoctorSchedule;
Activity context;
String fkscheduleid, DateofSlot;
int value_block;
int Doc_Id, fk_id, slot_id;
String timeofslot;
String tsId;
String time = "";
PostDoctorGetDoctorSchedule c = null;
int timeslot_id_value;
public PastAppointmentAdapter(Mainactivity3 context, ArrayList<PostDoctorGetDoctorSchedule> postDoctorGetDoctorSchedulepojo) {
this.context = context;
this.PostDoctorGetDoctorSchedule = postDoctorGetDoctorSchedulepojo;
}
@Override
public PastAppointmentsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_item_get_doctor_schedule, parent, false);
return new PastAppointmentsViewHolder(v);
}
@SuppressLint("LongLogTag")
@Override
public void onBindViewHolder(final PastAppointmentsViewHolder holder, final int position) {
final PostDoctorGetDoctorSchedule c = PostDoctorGetDoctorSchedule.get(position);
timeofslot=c.AvailableTimeSlots.get(position).getTimeOfSlot(); // I want to get "TimeOfSlot" values
// and "fkTimeId_block" which I'm adding in my main activity code
holder.tv_past_appointmentname.setText(timeofslot);
fk_id = c.GetBlockedTimings.get(position).getFkTimeId();
value_block=fk_id;
Log.e("DateofSlot11122", String.valueOf(fk_id));
String fk_value= String.valueOf(fk_id);
if(timeofslot==fk_value){
holder.tv_past_appointmentname.setTextColor(Color.RED);
}
holder.ll_row_item_get_doctor_schedule.setOnClickListener(new View.OnClickListener() {
@SuppressLint("LongLogTag")
@Override
public void onClick(View v) {
holder.btn_block1.setVisibility(View.VISIBLE);
}
});
holder.btn_block1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.tv_past_appointmentname.setTextColor(Color.parseColor("#ff0000"));
final Dialog lDialog = new Dialog(context);
lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
lDialog.setCancelable(false);
lDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
lDialog.getWindow().setDimAmount(.7f);
lDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
lDialog.getWindow().setElevation(4);
}
lDialog.setContentView(R.layout.popup_no_yes);
TextView tv_titiel = (TextView) lDialog.findViewById(R.id.tv_titiel);
TextView textMsg = (TextView) lDialog.findViewById(R.id.popup_msgs);
Button btnno = (Button) lDialog.findViewById(R.id.popup_no_btn);
Button btnyes = (Button) lDialog.findViewById(R.id.popup_yes_btn);
btnno.setTransformationMethod(null);
btnyes.setTransformationMethod(null);
tv_titiel.setText("Schedule");
textMsg.setText("Are you sure you want to block this slot?");
btnno.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lDialog.dismiss();
holder.tv_past_appointmentname.setTextColor(Color.parseColor("#000000"));
}
});
btnyes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.tv_past_appointmentname.setTextColor(Color.parseColor("#ff0000"));
timeslot_id_value=c.AvailableTimeSlots.get(position).getTimeSlotId();
fkscheduleid=c.getScheduleId();
DateofSlot=c.getDateOfSlot();
Toast.makeText(context,"click_value"+timeslot_id_value + " " + fkscheduleid,Toast.LENGTH_SHORT).show();
lDialog.dismiss();
}
});
lDialog.show();
}
});
}
@Override
public int getItemCount() {
return PostDoctorGetDoctorSchedule.size();
}
/*slot blocking*/
@SuppressLint("LongLogTag")
public String trimMessage(String json, String key) {
String trimmedString = null;
try {
JSONObject obj = new JSONObject(json);
trimmedString = obj.getString(key);
} catch (JSONException e) {
e.printStackTrace();
return null;
}
return trimmedString;
}
//Somewhere that has access to a context
public void displayMessage(String toastString) {
Toast.makeText(context, toastString, Toast.LENGTH_LONG).show();
}
}
public class PostDoctorGetDoctorSchedule
{
public String fkTimeId;
public String ScheduleId;
public ArrayList<AvailableTimeSlots> AvailableTimeSlots;
public String BlockId;
public int fkScheduledId;
public Boolean IsDeleted;
//public ArrayList<ArrayList<GetBlockedTimings>> GetBlockedTimings=new ArrayList<>();
public ArrayList<GetBlockedTimings> GetBlockedTimings;
public String DateOfSlot;
public String utcDateOfSlot;
public String getFkTimeId ()
{
return fkTimeId;
}
public void setFkTimeId (String fkTimeId)
{
this.fkTimeId = fkTimeId;
}
public String getScheduleId ()
{
return ScheduleId;
}
public void setScheduleId (String ScheduleId)
{
this.ScheduleId = ScheduleId;
}
public ArrayList<AvailableTimeSlots> getAvailableTimeSlots ()
{
return AvailableTimeSlots;
}
public void setAvailableTimeSlots (ArrayList<AvailableTimeSlots> AvailableTimeSlots)
{
this.AvailableTimeSlots = AvailableTimeSlots;
}
public String getBlockId ()
{
return BlockId;
}
public void setBlockId (String BlockId)
{
this.BlockId = BlockId;
}
public int getFkScheduledId ()
{
return fkScheduledId;
}
public void setFkScheduledId (int fkScheduledId)
{
this.fkScheduledId = fkScheduledId;
}
public Boolean getIsDeleted ()
{
return IsDeleted;
}
public void setIsDeleted (Boolean IsDeleted)
{
this.IsDeleted = IsDeleted;
}
// public List<ArrayList<GetBlockedTimings>> getGetBlockedTimings ()
// {
// return GetBlockedTimings;
// }
public ArrayList<GetBlockedTimings> getGetBlockedTimings ()
{
return GetBlockedTimings;
}
// public void setGetBlockedTimings (ArrayList<ArrayList<GetBlockedTimings>> GetBlockedTimings)
// {
// this.GetBlockedTimings = GetBlockedTimings;
// }
public void setGetBlockedTimings (ArrayList<GetBlockedTimings> GetBlockedTimings)
{
this.GetBlockedTimings = GetBlockedTimings;
}
public String getDateOfSlot ()
{
return DateOfSlot;
}
public void setDateOfSlot (String DateOfSlot)
{
this.DateOfSlot = DateOfSlot;
}
public String getUtcDateOfSlot ()
{
return utcDateOfSlot;
}
public void setUtcDateOfSlot (String utcDateOfSlot)
{
this.utcDateOfSlot = utcDateOfSlot;
}
@Override
public String toString()
{
return "ClassPojo [fkTimeId = "+fkTimeId+", ScheduleId = "+ScheduleId+", AvailableTimeSlots = "+AvailableTimeSlots+", BlockId = "+BlockId+", fkScheduledId = "+fkScheduledId+", IsDeleted = "+IsDeleted+", GetBlockedTimings = "+GetBlockedTimings+", DateOfSlot = "+DateOfSlot+", utcDateOfSlot = "+utcDateOfSlot+"]";
}
/*block time modal*/
public class GetBlockedTimings {
public int blockId;
public int fkTimeId;
public Boolean isDeleted;
public String BlockDateOfSlot;
public int fkScheduledId;
public ArrayList<AvailableTimeSlots> availableTimeSlots;
public ArrayList<GetBlockedTimings> GetBlockedTimings;
public ArrayList<AvailableTimeSlots> getAvailableTimeSlots() {
return availableTimeSlots;
}
public void setAvailableTimeSlots(ArrayList<AvailableTimeSlots> availableTimeSlots) {
this.availableTimeSlots = availableTimeSlots;
}
public ArrayList<GetBlockedTimings> getGetBlockedTimings() {
return GetBlockedTimings;
}
public void setGetBlockedTimings(ArrayList<GetBlockedTimings> getBlockedTimings) {
GetBlockedTimings = getBlockedTimings;
}
public String getBlockDateOfSlot() {
return BlockDateOfSlot;
}
public void setBlockDateOfSlot(String blockDateOfSlot) {
BlockDateOfSlot = blockDateOfSlot;
}
public int getBlockId() {
return blockId;
}
public void setBlockId(int blockId) {
this.blockId = blockId;
}
public int getFkTimeId() {
return fkTimeId;
}
public void setFkTimeId(int fkTimeId) {
this.fkTimeId = fkTimeId;
}
public Boolean getDeleted() {
return isDeleted;
}
public void setDeleted(Boolean deleted) {
isDeleted = deleted;
}
public int getFkScheduledId() {
return fkScheduledId;
}
public void setFkScheduledId(int fkScheduledId) {
this.fkScheduledId = fkScheduledId;
}
}
/*getavaliableslots*/
public class AvailableTimeSlots {
public int timeSlotId;
public String timeOfSlot;
public String timeofSlotDateTime;
public int getTimeSlotId() {
return timeSlotId;
}
public void setTimeSlotId(int timeSlotId) {
this.timeSlotId = timeSlotId;
}
public String getTimeOfSlot() {
return timeOfSlot;
}
public void setTimeOfSlot(String timeOfSlot) {
this.timeOfSlot = timeOfSlot;
}
public String getTimeofSlotDateTime() {
return timeofSlotDateTime;
}
public void setTimeofSlotDateTime(String timeofSlotDateTime) {
this.timeofSlotDateTime = timeofSlotDateTime;
}
}
}
我想通过json和volley而不是GSON来学习它。如果有任何符合我要求的示例,也可以分享。我已经发表了同样的问题,但到目前为止我没有收到有效的答复。这是一个卑鄙的要求,请在这里帮助我。在下面,我还提供了服务器响应。
服务器响应:-
{
"Response": {
"ResponseCode": 1,
"ResponseText": "Success"
},
"Detail": [
{
"DateOfSlot": "08/31/2018",
"AvailableTimeSlots": [
{
"TimeSlotId": 42,
"TimeOfSlot": "12:15 PM",
"TimeofSlotDateTime": "2018-08-31T12:15:00"
},
{
"TimeSlotId": 110,
"TimeOfSlot": "11:45 PM",
"TimeofSlotDateTime": "2018-08-31T23:45:00"
}
],
"ScheduleId": 4203,
"GetBlockedTimings": [
{
"DateOfSlot": "8/31/2018 12:00:00 AM",
"AvailableTimeSlots": null,
"ScheduleId": 0,
"GetBlockedTimings": null,
"BlockId": 1831,
"fkTimeId": 42,
"IsDeleted": false,
"fkScheduledId": 4203,
"utcDateOfSlot": "0001-01-01T00:00:00"
}
],
"BlockId": 0,
"fkTimeId": 0,
"IsDeleted": false,
"fkScheduledId": 0,
"utcDateOfSlot": "2018-08-31T00:00:00Z"
},
{
"DateOfSlot": "09/1/2018",
"AvailableTimeSlots": [
{
"TimeSlotId": 112,
"TimeOfSlot": "12:00 AM",
"TimeofSlotDateTime": "2018-09-01T00:00:00"
},
{
"TimeSlotId": 110,
"TimeOfSlot": "11:45 PM",
"TimeofSlotDateTime": "2018-09-01T23:45:00"
}
],
"ScheduleId": 4204,
"GetBlockedTimings": null,
"BlockId": 0,
"fkTimeId": 0,
"IsDeleted": false,
"fkScheduledId": 0,
"utcDateOfSlot": "2018-08-31T00:00:00Z"
},
{
"DateOfSlot": "09/2/2018",
"AvailableTimeSlots": [
{
"TimeSlotId": 112,
"TimeOfSlot": "12:00 AM",
"TimeofSlotDateTime": "2018-09-02T00:00:00"
},
{
"TimeSlotId": 110,
"TimeOfSlot": "11:45 PM",
"TimeofSlotDateTime": "2018-09-02T23:45:00"
}
],
"ScheduleId": 4205,
"GetBlockedTimings": null,
"BlockId": 0,
"fkTimeId": 0,
"IsDeleted": false,
"fkScheduledId": 0,
"utcDateOfSlot": "2018-09-01T00:00:00Z"
}
]
}
谢谢。