-1

I am a newbie to json parsing. I know how to parse a normal json object but I have no idea how to parse the kind of json I am listing below. Can someone help me on this?

I know how to parse this kind of json

[{"id":"1","image_title":"Android 1.5 Cupcake","image_url":"https://firebasestorage.googleapis.com/v0/b/sukshichat.appspot.com/o/Wrangler%2FIMG_20171102_141451.jpg?alt=media&token=ce3f2747-a36f-416d-9dfc-ecfb6be4b447"},{"id":"2","image_title":"Android 1.6 Donut","image_url":"https://firebasestorage.googleapis.com/v0/b/sukshichat.appspot.com/o/Wrangler%2FIMG_20171102_141451.jpg?alt=media&token=ce3f2747-a36f-416d-9dfc-ecfb6be4b447"},{"id":"3","image_title":"Android 2.0 Eclair","image_url":"https://firebasestorage.googleapis.com/v0/b/sukshichat.appspot.com/o/Wrangler%2FIMG_20171102_141451.jpg?alt=media&token=ce3f2747-a36f-416d-9dfc-ecfb6be4b447"},{"id":"4","image_title":"Android 2.2 Froyo","image_url":"https://firebasestorage.googleapis.com/v0/b/sukshichat.appspot.com/o/Wrangler%2FIMG_20171102_141451.jpg?alt=media&token=ce3f2747-a36f-416d-9dfc-ecfb6be4b447"},{"id":"5","image_title":"Android 2.3 GingerBread","image_url":"https://firebasestorage.googleapis.com/v0/b/sukshichat.appspot.com/o/Wrangler%2FIMG_20171102_141451.jpg?alt=media&token=ce3f2747-a36f-416d-9dfc-ecfb6be4b447"},{"id":"6","image_title":"Android 3.0 HoneyComb","image_url":"https://firebasestorage.googleapis.com/v0/b/sukshichat.appspot.com/o/Wrangler%2FIMG_20171102_141451.jpg?alt=media&token=ce3f2747-a36f-416d-9dfc-ecfb6be4b447"},{"id":"7","image_title":"Android 4.0 Ice Cream Sandwich","image_url":"https://firebasestorage.googleapis.com/v0/b/sukshichat.appspot.com/o/Wrangler%2FIMG_20171102_141451.jpg?alt=media&token=ce3f2747-a36f-416d-9dfc-ecfb6be4b447"},{"id":"8","image_title":"Android 4.1 Jelly Bean","image_url":"https://firebasestorage.googleapis.com/v0/b/sukshichat.appspot.com/o/Wrangler%2FIMG_20171102_141451.jpg?alt=media&token=ce3f2747-a36f-416d-9dfc-ecfb6be4b447"},{"id":"9","image_title":"Android 4.4 KitKat","image_url":"https://firebasestorage.googleapis.com/v0/b/sukshichat.appspot.com/o/Wrangler%2FIMG_20171102_141451.jpg?alt=media&token=ce3f2747-a36f-416d-9dfc-ecfb6be4b447"}]

But I have no Idea on how to parse this and append the values in recyclerview.

    {
    "id": {
        "0": "1",
        "5": "2",
        "6": "3",
        "10": "4",
        "12": "5"
    },
    "image_title": {
        "0": "Blue",
        "5": "Black",
        "6": "Yellow",
        "10": "Orange",
        "12": "Voilet"
    }
}

My Full JSON Response

    {
  "Store EAN Number": {
    "0": null,
    "5": null,
    "6": null,
    "10": null,
    "12": null
  },
  "SKU Code": {
    "0": null,
    "5": null,
    "6": null,
    "10": null,
    "12": null
  },
  "Mihu EAN Number": {
    "0": 9999922000001,
    "5": 9999922000006,
    "6": 9999922000007,
    "10": 9999922000011,
    "12": 9999922000013
  },
  "Style Code": {
    "0": "Vico0001",
    "5": "Vico0006",
    "6": "Vico0007",
    "10": "Vico0011",
    "12": "Vico0013"
  },
  "Store": {
    "0": "Vision Colour",
    "5": "Vision Colour",
    "6": "Vision Colour",
    "10": "Vision Colour",
    "12": "Vision Colour"
  },
  "Store Code": {
    "0": 22,
    "5": 22,
    "6": 22,
    "10": 22,
    "12": 22
  },
  "Category": {
    "0": "Shirt",
    "5": "Shirt",
    "6": "Shirt",
    "10": "Shirt",
    "12": "Shirt"
  },
  "Gender": {
    "0": "Male",
    "5": "Male",
    "6": "Male",
    "10": "Male",
    "12": "Male"
  },
  "Sleeves Type": {
    "0": "Full Sleeve",
    "5": "Full Sleeve",
    "6": "Full Sleeve",
    "10": "Full Sleeve",
    "12": "Full Sleeve"
  },
  "Collection": {
    "0": "Casual",
    "5": "Casual",
    "6": "Casual",
    "10": "Casual",
    "12": "Casual"
  },
  "Fitting Type": {
    "0": "Slim",
    "5": "Slim",
    "6": "Slim",
    "10": "Slim",
    "12": "Slim"
  },
  " Size ": {
    "0": "M",
    "5": "M",
    "6": "M",
    "10": "M",
    "12": "M"
  },
  "Pocket Type": {
    "0": "No Pocket",
    "5": "V Shape",
    "6": "V Shape",
    "10": "V Shape",
    "12": "V Shape"
  },
  "Fabric Type": {
    "0": "100% cotton",
    "5": "100% cotton",
    "6": "100% cotton",
    "10": "100% cotton",
    "12": "100% cotton"
  },
  "Colour": {
    "0": "White",
    "5": "White",
    "6": "White",
    "10": "White",
    "12": "White"
  },
  "Fabric Design": {
    "0": "Printed",
    "5": "Printed",
    "6": "Printed",
    "10": "Printed",
    "12": "Printed"
  },
  "garment_description": {
    "0": null,
    "5": null,
    "6": null,
    "10": null,
    "12": null
  },
  "garment_name": {
    "0": "White Full Sleeve Printed Shirt",
    "5": "White Full Sleeve Printed Shirt",
    "6": "White Full Sleeve Printed Shirt",
    "10": "White Full Sleeve Printed Shirt",
    "12": "White Full Sleeve Printed Shirt"
  },
  "mrp_price": {
    "0": 450,
    "5": 450,
    "6": 450,
    "10": 450,
    "12": 450
  },
  "discount_price": {
    "0": null,
    "5": null,
    "6": null,
    "10": null,
    "12": null
  }

}
Stackover67
  • 347
  • 2
  • 4
  • 18

1 Answers1

1

Parse like this:

JsonObject jsonObj = new JsonObject(response);

JsonObject id_jsonObj = jsonObj.getJsonObject("id");

String first = id_jsonObj.getString("0");

String second = id_jsonObj.getString("5");

//and so on

JsonObject image_jsonObj = jsonObj.getJsonObject("image_title");

String title1 = image_jsonObj.getString("0");

String title2 = image_jsonObj.getString("5");

//and so on
Maddy
  • 4,525
  • 4
  • 33
  • 53
rastha67
  • 851
  • 1
  • 6
  • 13
  • The id's 0,5, are not same all the time. can you explain how to get them dynamically – Stackover67 Dec 04 '17 at 09:12
  • you can get id's like this: JSONArray names = id_jsonObj.names(); for (int i = 0; i < names.length(); i++) { Log.e("names", names.getString(i)); } – rastha67 Dec 04 '17 at 11:50