使用Realm解析嵌套的json?

时间:2017-04-17 16:47:39

标签: android json parsing nested realm

我有POJOS预约,付款历史,SOP,SubService,偏好         我的问题是我想将所有json字段存储在一个POJO.i.e的Arraylist中。 Java Object。因为在解析之后,只有一个arraylist将用于基本适配器。

         "data": [
            {
              "userId": "10088",
              "appointments": [
                {
                  "id": "2185640",
                  "service_name": "Physiotherapy",
                  "subservice": [
                    {
                      "id": "107",
                      "subserviceName": "ELECTRICAL STIMULATION",
                      "subservice_price": 100
                    },
                    {
                      "id": "139",
                      "subserviceName": "ERGONOMIC CONSULTATION",
                      "subservice_price": 100
                    }
                  ],
                  "total_subservice_price": 200,
                  "price_excluding_subservice": 750,
                  "preference": [],
                  "visit_count": 1,
                  "payment_history": [
                    {
                      "amountReceived": "200.00",
                      "mode": "cash",
                      "notes": "",

                    }
                  ],
                  "sop": {
                    "sop_count": "2"
                  },
                  "EOS": true
                },   
              ],
              "mapped_address": 0,
              "last_id": "34"
            }
          ]
        }


    POJOs created:

        public class AppointmentMain extends RealmObject {
        @PrimaryKey
            private int id;

            public int getId() {
                return id;
            }

            public void setId(int id) {
                this.id = id;
            }

            private static RealmList<DataPojo> data;

            public RealmList<DataPojo> getData() {
                return data;
            }

            public void setData(RealmList<DataPojo> data) {
                this.data = data;
            }

            public AppointmentMain() {
            }

            @Override
            public String toString() {
                return "ClassPojo [data = " + data + "]";
            }
        }



    Data pojo

        public class DataPojo extends RealmObject {


                private String mapped_address;

                private RealmList<Appointmnt> appointments;

                public DataPojo() {
                }

                private String last_id;

                private String userId;

                public String getMapped_address() {
                    return mapped_address;
                }

                public void setMapped_address(String mapped_address) {
                    this.mapped_address = mapped_address;
                }

                public RealmList<Appointmnt> getAppointments() {
                    return appointments;
                }

                public void setAppointments(RealmList<Appointmnt> appointments) {
                    this.appointments = appointments;
                }

                public String getLast_id() {
                    return last_id;
                }

                public void setLast_id(String last_id) {
                    this.last_id = last_id;
                }

                public String getUserId() {
                    return userId;
                }

                public void setUserId(String userId) {
                    this.userId = userId;
                }

                @Override
                public String toString() {
                    return "ClassPojo [mapped_address = " + mapped_address + ", appointments = " + appointments + ", last_id = " + last_id + ", userId = " + userId + "]";
                }
            }
    Appointment POJO:

    public class Appointmnt extends RealmObject {

        private String service_id;

        private String isTrial;

        private String packageName;

        private String location;

        private String is_assessment;

        private String empId;

        private int packageId;

        private int case_sheet_id;

        private String service_name;

        private String case_sheet_type;

        private String type;

        private String brand_name;

        private int reschedule_count;

        private String substatus;

        private String emailId;

        private String phoneNumber;

        private String related_appt_id;

        private int age;

        private String gender;

        private String longitude;

        private String total_subservice_price;

        private RealmList<SubService> subservice;

        private int canViewContact;

        private String status;

        private int brand_id;

        private String service_protocol;

        private Sop sop;

        private int cost;

        private int deleted;

        private String patient_status;

        private boolean EOS;

        private int discount;

        private int fee;

        private String createdOn;

        private String latitude;

        private  int canCollectPayment;
        private int visit_count;

        private int area_id;

        private String dateTime;

        private String prof_name;

        private int id;

        private String price_excluding_subservice;

        private String area_name;

        private String diagnostic_partner;

        private int payment;

        private String patient_name;

        private int service_type_id;

        private String duration;

        private RealmList<Preference> preference;

        private String address;

        private int packageFee;

        private RealmList<Payment_history> payment_history;

        private int case_id;

        private int patient_id;

        private String mobileNumber;

        private String salutation;
        private  String location_verified;

        public boolean isEOS() {
            return EOS;
        }



        public void setPayment_history(RealmList<Payment_history> payment_history) {
            this.payment_history = payment_history;
        }

        public String getLocation_verified() {
            return location_verified;
        }

        public void setLocation_verified(String location_verified) {
            this.location_verified = location_verified;
        }

        public Appointmnt() {
        }

        public String getService_id ()
        {
            return service_id;
        }

        public void setService_id (String service_id)
        {
            this.service_id = service_id;
        }

        public String getIsTrial ()
        {
            return isTrial;
        }

        public void setIsTrial (String isTrial)
        {
            this.isTrial = isTrial;
        }

        public String getPackageName ()
        {
            return packageName;
        }

        public void setPackageName (String packageName)
        {
            this.packageName = packageName;
        }

        public String getLocation ()
        {
            return location;
        }

        public void setLocation (String location)
        {
            this.location = location;
        }

        public String getIs_assessment ()
        {
            return is_assessment;
        }

        public void setIs_assessment (String is_assessment)
        {
            this.is_assessment = is_assessment;
        }

        public String getEmpId ()
        {
            return empId;
        }

        public void setEmpId (String empId)
        {
            this.empId = empId;
        }

        public int getPackageId ()
        {
            return packageId;
        }

        public void setPackageId (int packageId)
        {
            this.packageId = packageId;
        }

        public int getCase_sheet_id ()
        {
            return case_sheet_id;
        }

        public void setCase_sheet_id (int case_sheet_id)
        {
            this.case_sheet_id = case_sheet_id;
        }

        public String getService_name ()
        {
            return service_name;
        }

        public void setService_name (String service_name)
        {
            this.service_name = service_name;
        }

        public String getCase_sheet_type ()
        {
            return case_sheet_type;
        }

        public void setCase_sheet_type (String case_sheet_type)
        {
            this.case_sheet_type = case_sheet_type;
        }

        public String getType ()
        {
            return type;
        }

        public void setType (String type)
        {
            this.type = type;
        }

        public String getBrand_name ()
        {
            return brand_name;
        }

        public void setBrand_name (String brand_name)
        {
            this.brand_name = brand_name;
        }

        public int getReschedule_count ()
        {
            return reschedule_count;
        }

        public void setReschedule_count (int reschedule_count)
        {
            this.reschedule_count = reschedule_count;
        }

        public String getSubstatus ()
        {
            return substatus;
        }

        public void setSubstatus (String substatus)
        {
            this.substatus = substatus;
        }

        public String getEmailId ()
        {
            return emailId;
        }

        public void setEmailId (String emailId)
        {
            this.emailId = emailId;
        }

        public String getPhoneNumber ()
        {
            return phoneNumber;
        }

        public void setPhoneNumber (String phoneNumber)
        {
            this.phoneNumber = phoneNumber;
        }

        public String getRelated_appt_id ()
        {
            return related_appt_id;
        }

        public void setRelated_appt_id (String related_appt_id)
        {
            this.related_appt_id = related_appt_id;
        }

        public int getAge ()
        {
            return age;
        }

        public void setAge (int age)
        {
            this.age = age;
        }

        public String getGender ()
        {
            return gender;
        }

        public void setGender (String gender)
        {
            this.gender = gender;
        }

        public String getLongitude ()
        {
            return longitude;
        }

        public void setLongitude (String longitude)
        {
            this.longitude = longitude;
        }

        public String getTotal_subservice_price ()
        {
            return total_subservice_price;
        }

        public void setTotal_subservice_price (String total_subservice_price)
        {
            this.total_subservice_price = total_subservice_price;
        }

        public RealmList<SubService> getSubservice ()
        {
            return subservice;
        }

        public void setSubservice (RealmList<SubService> subservice)
        {
            this.subservice = subservice;
        }

        public int getCanViewContact ()
        {
            return canViewContact;
        }

        public void setCanViewContact (int canViewContact)
        {
            this.canViewContact = canViewContact;
        }

        public String getStatus ()
        {
            return status;
        }

        public void setStatus (String status)
        {
            this.status = status;
        }

        public int getBrand_id ()
        {
            return brand_id;
        }

        public void setBrand_id (int brand_id)
        {
            this.brand_id = brand_id;
        }

        public String getService_protocol ()
        {
            return service_protocol;
        }

        public void setService_protocol (String service_protocol)
        {
            this.service_protocol = service_protocol;
        }

        public Sop getSop ()
        {
            return sop;
        }

        public void setSop (Sop sop)
        {
            this.sop = sop;
        }

        public int getCost ()
        {
            return cost;
        }

        public void setCost (int cost)
        {
            this.cost = cost;
        }

        public int getDeleted ()
        {
            return deleted;
        }

        public void setDeleted (int deleted)
        {
            this.deleted = deleted;
        }

        public String getPatient_status ()
        {
            return patient_status;
        }

        public void setPatient_status (String patient_status)
        {
            this.patient_status = patient_status;
        }

        public boolean getEOS ()
        {
            return EOS;
        }

        public void setEOS (boolean EOS)
        {
            this.EOS = EOS;
        }

        public int getDiscount ()
        {
            return discount;
        }

        public void setDiscount (int discount)
        {
            this.discount = discount;
        }

        public int getFee ()
        {
            return fee;
        }

        public void setFee (int fee)
        {
            this.fee = fee;
        }

        public String getCreatedOn ()
        {
            return createdOn;
        }

        public void setCreatedOn (String createdOn)
        {
            this.createdOn = createdOn;
        }

        public String getLatitude ()
        {
            return latitude;
        }

        public void setLatitude (String latitude)
        {
            this.latitude = latitude;
        }

        public int getCanCollectPayment ()
        {
            return canCollectPayment;
        }

        public void setCanCollectPayment (int canCollectPayment)
        {
            this.canCollectPayment = canCollectPayment;
        }

        public int getVisit_count ()
        {
            return visit_count;
        }

        public void setVisit_count (int visit_count)
        {
            this.visit_count = visit_count;
        }

        public int getArea_id ()
        {
            return area_id;
        }

        public void setArea_id (int area_id)
        {
            this.area_id = area_id;
        }

        public String getDateTime ()
        {
            return dateTime;
        }

        public void setDateTime (String dateTime)
        {
            this.dateTime = dateTime;
        }

        public String getProf_name ()
        {
            return prof_name;
        }

        public void setProf_name (String prof_name)
        {
            this.prof_name = prof_name;
        }

        public int getId ()
        {
            return id;
        }

        public void setId (int id)
        {
            this.id = id;
        }

        public String getPrice_excluding_subservice ()
        {
            return price_excluding_subservice;
        }

        public void setPrice_excluding_subservice (String price_excluding_subservice)
        {
            this.price_excluding_subservice = price_excluding_subservice;
        }

        public String getArea_name ()
        {
            return area_name;
        }

        public void setArea_name (String area_name)
        {
            this.area_name = area_name;
        }

        public String getDiagnostic_partner ()
        {
            return diagnostic_partner;
        }

        public void setDiagnostic_partner (String diagnostic_partner)
        {
            this.diagnostic_partner = diagnostic_partner;
        }

        public int getPayment ()
        {
            return payment;
        }

        public void setPayment (int payment)
        {
            this.payment = payment;
        }

        public String getPatient_name ()
        {
            return patient_name;
        }

        public void setPatient_name (String patient_name)
        {
            this.patient_name = patient_name;
        }

        public int getService_type_id ()
        {
            return service_type_id;
        }

        public void setService_type_id (int service_type_id)
        {
            this.service_type_id = service_type_id;
        }

        public String getDuration ()
        {
            return duration;
        }

        public void setDuration (String duration)
        {
            this.duration = duration;
        }

        public RealmList<Preference> getPreference ()
        {
            return preference;
        }

        public void setPreference (RealmList<Preference> preference)
        {
            this.preference = preference;
        }

        public String  getAddress ()
        {
            return address;
        }

        public void setAddress (String address)
        {
            this.address = address;
        }

        public int getPackageFee ()
        {
            return packageFee;
        }

        public void setPackageFee (int packageFee)
        {
            this.packageFee = packageFee;
        }


        public int getCase_id ()
        {
            return case_id;
        }

        public void setCase_id (int case_id)
        {
            this.case_id = case_id;
        }

        public int getPatient_id ()
        {
            return patient_id;
        }

        public void setPatient_id (int patient_id)
        {
            this.patient_id = patient_id;
        }

        public String getMobileNumber ()
        {
            return mobileNumber;
        }

        public void setMobileNumber (String mobileNumber)
        {
            this.mobileNumber = mobileNumber;
        }

        public String getSalutation ()
        {
            return salutation;
        }

        public void setSalutation (String salutation)
        {
            this.salutation = salutation;
        }

        @Override
        public String toString()
        {
            return "ClassPojo [service_id = "+service_id+", isTrial = "+isTrial+", packageName = "+packageName+", location = "+location+", is_assessment = "+is_assessment+", empId = "+empId+", packageId = "+packageId+", case_sheet_id = "+case_sheet_id+", service_name = "+service_name+", case_sheet_type = "+case_sheet_type+", type = "+type+", brand_name = "+brand_name+", reschedule_count = "+reschedule_count+", substatus = "+substatus+", emailId = "+emailId+", phoneNumber = "+phoneNumber+", related_appt_id = "+related_appt_id+", age = "+age+", gender = "+gender+", longitude = "+longitude+", total_subservice_price = "+total_subservice_price+", subservice = "+subservice+", canViewContact = "+canViewContact+", status = "+status+", brand_id = "+brand_id+", service_protocol = "+service_protocol+", sop = "+sop+", cost = "+cost+", deleted = "+deleted+", patient_status = "+patient_status+", EOS = "+EOS+", discount = "+discount+", fee = "+fee+", createdOn = "+createdOn+", latitude = "+latitude+", canCollectPayment = "+canCollectPayment+", visit_count = "+visit_count+", area_id = "+area_id+", dateTime = "+dateTime+", prof_name = "+prof_name+", id = "+id+", price_excluding_subservice = "+price_excluding_subservice+", area_name = "+area_name+", diagnostic_partner = "+diagnostic_partner+", payment = "+payment+", patient_name = "+patient_name+", service_type_id = "+service_type_id+", duration = "+duration+", preference = "+preference+", address = "+address+", packageFee = "+packageFee+", payment_history = "+payment_history+", case_id = "+case_id+", patient_id = "+patient_id+", mobileNumber = "+mobileNumber+", salutation = "+salutation+"]";
        }

        public RealmList<Payment_history> getPayment_history() {
            return payment_history;
        }
    }

    Payment_History POJO
    public class Payment_history  extends RealmObject{
        private String createdOn;

        private String amountReceived;

        private String receiverName;

        private String notes;

        private String receiverEmailId;

        private String mode;

        public Payment_history(String createdOn, String amountReceived, String receiverName, String notes, String receiverEmailId, String mode) {
            this.createdOn = createdOn;
            this.amountReceived = amountReceived;
            this.receiverName = receiverName;
            this.notes = notes;
            this.receiverEmailId = receiverEmailId;
            this.mode = mode;
        }


        public String getCreatedOn ()
        {
            return createdOn;
        }

        public void setCreatedOn (String createdOn)
        {
            this.createdOn = createdOn;
        }

        public String getAmountReceived ()
        {
            return amountReceived;
        }

        public void setAmountReceived (String amountReceived)
        {
            this.amountReceived = amountReceived;
        }

        public String getReceiverName ()
        {
            return receiverName;
        }

        public void setReceiverName (String receiverName)
        {
            this.receiverName = receiverName;
        }

        public String getNotes ()
        {
            return notes;
        }

        public void setNotes (String notes)
        {
            this.notes = notes;
        }

        public String getReceiverEmailId ()
        {
            return receiverEmailId;
        }

        public void setReceiverEmailId (String receiverEmailId)
        {
            this.receiverEmailId = receiverEmailId;
        }

        public String getMode ()
        {
            return mode;
        }

        public void setMode (String mode)
        {
            this.mode = mode;
        }

        public Payment_history() {
        }

        @Override
        public String toString()
        {
            return "ClassPojo [createdOn = "+createdOn+", amountReceived = "+amountReceived+", receiverName = "+receiverName+", notes = "+notes+", receiverEmailId = "+receiverEmailId+", mode = "+mode+"]";
        }
    }
Preference POJO:

public class Preference extends RealmObject {
private  int id;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Preference() {
    }
}

SOP POJO

public class Sop extends RealmObject {
    private  int sop_count;

    public int getSop_count() {
        return sop_count;
    }

    public void setSop_count(int sop_count) {
        this.sop_count = sop_count;
    }

    public Sop() {
    }
}

SubService POJO:
public class SubService  extends RealmObject{

    private int id;
    private String subserviceName;
    private  double subservice_price;


    public SubService() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getSubserviceName() {
        return subserviceName;
    }

    public void setSubserviceName(String subserviceName) {
        this.subserviceName = subserviceName;
    }

    public double getSubservice_price() {
        return subservice_price;
    }

    public void setSubservice_price(double subservice_price) {
        this.subservice_price = subservice_price;
    }
}

0 个答案:

没有答案