0
{
  "status": "1",
  "message": "",
  "result": {
    "info": {
      "tax": "0",
      "discount": "0",
      "minimum_spend": "300",
      "delivery_charges": "0",
      "last_updated": "1 week 15 hours ago"
    },
    "items": [
      {
        "name": "Eat At Home",
        "menu_item_id": "12345",
        "menu_cat_id": "4321",
        "menu_cat_sku": "",
        "nutritions": "",
        "price": "1000",
        "currency": "USD",
        "desc": "Desription",
        "category": "Promotion",
        "image": "https://static.google.com/media/images/thumbs/343e8f41b18325a6058adc3773ed4d53.png",
        "large_image": "https://static.google.com/media/images/343e8f41b18325a6058adc3773ed4d53.png",
        "options": [],
        "discount": "",
        "weight": "",
        "sku": "",
        "status": "0",
        "brand": []
      },
      {
        "name": "Lunch Bundle",
        "menu_item_id": "4321",
        "menu_cat_id": "4321",
        "menu_cat_sku": "",
        "nutritions": "",
        "price": "1500",
        "currency": "USD",
        "desc": "Description",
        "category": "Promotion",
        "image": "https://static.google.com/media/images/thumbs/62cdde279bbc3e45b8456f040d649b32.png",
        "large_image": "https://static.google.com/media/images/62cdde279bbc3e45b8456f040d649b32.png",
        "options": [],
        "discount": "",
        "weight": "",
        "sku": "",
        "status": "0",
        "brand": []
      },

My code

MenuResponse menuResponse = JsonParser.getInstance().parseMenuResponse(response);


public MenuResponse parseMenuResponse(String serverResponse) throws Exception {

    MenuResponse response = null;

    if (serverResponse != null) {
        try {
            response = gson.fromJson(serverResponse, MenuResponse.class);
        } catch (JsonSyntaxException jse) {
            throw new Exception(ERROR_MESSAGE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return response;
}
3
  • Are you facing any issue ? Commented Feb 20, 2019 at 6:15
  • yes how can i show child views in recyclerview ? Commented Feb 21, 2019 at 6:02
  • What do you mean by child view can you please give more detail Commented Feb 21, 2019 at 7:20

1 Answer 1

1

try this.

JSONObject json = new JSONObject(response);

 String status= json.getString("status");
 JSONArray itemsArray= json.getJSONArray("items");

for (int i = 0; i < itemsArray.length(); i++) {
 JSONObject c = itemsArray.getJSONObject(i);
 String name= c.getString("name");
 //remaining data you will 
}

Or else better you can use Retrofit.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.