解析不同类型的json对象并在recyclerview中列出数据

时间:2017-12-04 07:19:00

标签: java android json

我是json解析的新手。我知道如何解析一个普通的json对象,但我不知道如何解析我在下面列出的那种json。有人可以帮我吗?

我知道如何解析这种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"}]

但我不知道如何解析这个并将值附加到recyclerview中。

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

我的完整JSON响应

    {
  "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
  }

}

1 个答案:

答案 0 :(得分:0)

解析如下:

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