पुराना वापस के साथ प्रतिक्रिया प्राप्त करने के लिए नेस्टेड json के POJO फ़ाइल बनाने के लिए कैसे

वोट
-1
How can I create pojo file for nested json to get response with retrofit.
Follwing are my json.
{
    Category_Name: [
        Breads,
        Combo and Thali,
        Main Course,
        Rice and Biryani
    ],
    Alldishitems: [
        [
            {
                Subcategory: Brown bread,
                DishName: Stuffed Paratha,
                DishPrice: 100,
                Dishquantity: 10,
                Dishdescription: 
            },
            {
                Subcategory: white Bread,
                DishName: Plain Paratha,
                DishPrice: 136,
                Dishquantity: 10,
                Dishdescription: 
            }
        ],
        [
            {
                Subcategory: Combo,
                DishName: Rajma Masala Combo,
                DishPrice: 136,
                Dishquantity: 10,
                Dishdescription: 
            },
            {
                Subcategory: Combo,
                DishName: Lassi with Aloo Paratha,
                DishPrice: 100,
                Dishquantity: 10,
                Dishdescription: 
            },
            {
                Subcategory: Thali,
                DishName: Chinise thali,
                DishPrice: 100,
                Dishquantity: 10,
                Dishdescription: 
            }
        ],
]

Follwing code I have tried but getting null


public class ServerResponse {
    @SerializedName(Category_Name)
    String[] Category_Name;
    @SerializedName(Alldishitems)
    ArrayList<ArrayList<Getmenulist>>getmenudata = new  ArrayList<ArrayList<Getmenulist>>();

    public  ServerResponse(String[] category_Name,ArrayList<ArrayList<Getmenulist>> getmenudata)
    {
        this.Category_Name=category_Name;
        this.getmenudata=getmenudata;
    }

    public String[] getCategory_Name() {
        return Category_Name;
    }

    public ArrayList<ArrayList<Getmenulist>>getGetmenudata() {
        return getmenudata;
    }


}

public class Getmenulist {
    @SerializedName(Alldishitems)
    List<Getmenulist.Getmenudata> data;
    public Getmenulist(List<Getmenulist.Getmenudata> data)
    {
        this.data=data;
    }

    public List<Getmenulist.Getmenudata> getData() {
        return data;
    }
    public class Getmenudata {
        @SerializedName(Subcategory)
        String Subcategory;
        @SerializedName(DishName)
        String DishName;
        @SerializedName(DishPrice)
        String DishPrice;
        @SerializedName(Dishquantity)
        String dishQuantities;
        @SerializedName(Dishdescription)
        String Dishdescription;
        @SerializedName(image)
        String image;


        public Getmenudata(String Subcategory, String DishName, String DishPrice, String dishQuantities, String Dishdescription, String image) {
            this.Subcategory = Subcategory;
            this.DishName = DishName;
            this.DishPrice = DishPrice;
            this.dishQuantities = dishQuantities;
            this.Dishdescription = Dishdescription;
            this.image = image;

        }

        public String getDishdescription() {
            return Dishdescription;
        }

        public String getImage() {
            return image;
        }

        public String getDishName() {
            return DishName;
        }

        public String getDishPrice() {
            return DishPrice;
        }

        public String getDishQuantities() {
            return dishQuantities;
        }

        public String getSubcategory() {
            return Subcategory;
        }

    }
}

कोड से ऊपर मैंने कोशिश की है, लेकिन हो रही null.I सरणी के आकार मिल गया लेकिन वहाँ डेटा है.और में नहीं है तो आपके न मन कृपया मेरी मदद करो इस समस्या को बाहर निकालने के लिए। मैं json या POJO फ़ाइल को बदलने की जरूरत है। मैं चिपचिपा सूची के लिए डेटा लाने की कोशिश कर रहा हूँ। श्रेणी की तरह मेरे डेटा तो उपश्रेणी और उस डेटा की उस सूची के बाद।

09/10/2019 को 12:58
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


2 जवाब

वोट
0

1. अपने json प्रारूप गलत है। यहाँ अद्यतन json है:

{ 
   "Category_Name":[ 
      "Breads",
      "Combo and Thali",
      "Main Course",
      "Rice and Biryani"
   ],
   "Alldishitems":[ 
      [ 
         { 
            "Subcategory":"Brown bread",
            "DishName":"Stuffed Paratha",
            "DishPrice":"100",
            "Dishquantity":"10",
            "Dishdescription":""
         },
         { 
            "Subcategory":"white Bread",
            "DishName":"Plain Paratha",
            "DishPrice":"136",
            "Dishquantity":"10",
            "Dishdescription":""
         }
      ],
      [ 
         { 
            "Subcategory":"Combo",
            "DishName":"Rajma Masala Combo",
            "DishPrice":"136",
            "Dishquantity":"10",
            "Dishdescription":""
         },
         { 
            "Subcategory":"Combo",
            "DishName":"Lassi with Aloo Paratha",
            "DishPrice":"100",
            "Dishquantity":"10",
            "Dishdescription":""
         },
         { 
            "Subcategory":"Thali",
            "DishName":"Chinise thali",
            "DishPrice":"100",
            "Dishquantity":"10",
            "Dishdescription":""
         }
      ]
   ]
}

2. इस JSON फ़ाइल के लिए दो वर्गों होनी चाहिए:

  1. YourName.java
public class PojoClass
{
    private String[] Category_Name;

    private Alldishitems[][] Alldishitems;

    public String[] getCategory_Name ()
    {
        return Category_Name;
    }

    public void setCategory_Name (String[] Category_Name)
    {
        this.Category_Name = Category_Name;
    }

    public Alldishitems[][] getAlldishitems ()
    {
        return Alldishitems;
    }

    public void setAlldishitems (Alldishitems[][] Alldishitems)
    {
        this.Alldishitems = Alldishitems;
    }

    @Override
    public String toString()
    {
        return "ClassPojo [Category_Name = "+Category_Name+", Alldishitems = "+Alldishitems+"]";
    }
}
  1. Allitems.java
public class Alldishitems
{
    private String Subcategory;

    private String DishPrice;

    private String Dishquantity;

    private String Dishdescription;

    private String DishName;

    public String getSubcategory ()
    {
        return Subcategory;
    }

    public void setSubcategory (String Subcategory)
    {
        this.Subcategory = Subcategory;
    }

    public String getDishPrice ()
    {
        return DishPrice;
    }

    public void setDishPrice (String DishPrice)
    {
        this.DishPrice = DishPrice;
    }

    public String getDishquantity ()
    {
        return Dishquantity;
    }

    public void setDishquantity (String Dishquantity)
    {
        this.Dishquantity = Dishquantity;
    }

    public String getDishdescription ()
    {
        return Dishdescription;
    }

    public void setDishdescription (String Dishdescription)
    {
        this.Dishdescription = Dishdescription;
    }

    public String getDishName ()
    {
        return DishName;
    }

    public void setDishName (String DishName)
    {
        this.DishName = DishName;
    }

    @Override
    public String toString()
    {
        return "ClassPojo [Subcategory = "+Subcategory+", DishPrice = "+DishPrice+", Dishquantity = "+Dishquantity+", Dishdescription = "+Dishdescription+", DishName = "+DishName+"]";
    }
}

नोट : कोड से अनावश्यक चीजों को निकाल दें।

आशा है कि यह आपकी मदद करेगा। खुश होती है।

09/10/2019 को 13:19
का स्रोत उपयोगकर्ता

वोट
0

त्रुटि ServerResponse कक्षा में है, getmenudata एक ArrayList <ArrayList <... >> पहले से ही है क्योंकि इस बात Germenulist वर्ग कोशिश में एक सूची नहीं है:

public class ServerResponse {
    @SerializedName("Category_Name")
    String[] Category_Name;
    @SerializedName("Alldishitems")
    List<Getmenulist> getmenudata = new ArrayList<Getmenulist>();

    public ServerResponse(String[] category_Name, ArrayList<Getmenulist> getmenudata) {
        this.Category_Name = category_Name;
        this.getmenudata = getmenudata;
    }

    public String[] getCategory_Name() {
        return Category_Name;
    }

    public List<Getmenulist> getGetmenudata() {
        return getmenudata;
    }


}

public class Getmenulist {

    @SerializedName("Alldishitems")
    List<Getmenudata> data;

    public Getmenulist(List<Getmenulist.Getmenudata> data) {
        this.data = data;
    }

    public class Getmenudata {
        @SerializedName("Subcategory")
        String Subcategory;
        @SerializedName("DishName")
        String DishName;
        @SerializedName("DishPrice")
        String DishPrice;
        @SerializedName("Dishquantity")
        String dishQuantities;
        @SerializedName("Dishdescription")
        String Dishdescription;
        @SerializedName("image")
        String image;


        public Getmenudata(String Subcategory, String DishName, String DishPrice, String dishQuantities, String Dishdescription, String image) {
            this.Subcategory = Subcategory;
            this.DishName = DishName;
            this.DishPrice = DishPrice;
            this.dishQuantities = dishQuantities;
            this.Dishdescription = Dishdescription;
            this.image = image;

        }

        public String getDishdescription() {
            return Dishdescription;
        }

        public String getImage() {
            return image;
        }

        public String getDishName() {
            return DishName;
        }

        public String getDishPrice() {
            return DishPrice;
        }

        public String getDishQuantities() {
            return dishQuantities;
        }

        public String getSubcategory() {
            return Subcategory;
        }
    }

}
09/10/2019 को 13:10
का स्रोत उपयोगकर्ता

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more