-1

The array has got one string named childrenand inside that children there can be another children and inside that children again another children.Please help me with how to parse this The format of json is like this I have one json response which has array's inside array's . I want to fetch all the values of a given tag.

{
    "id": "fe13e84e-fa26-46fb-bd39-6b581dad9eb7",
    "type": "data",
    "title": "root",
    "children": [
{
    "id": "d6426ce9-e243-40b1-93f5-a1aaa3193a4c",
    "type": "group",
    "title": "first",
    "children": [
     {
    "id": "b3d888b1-c4f0-4337-87a3-d51961d81c0b",
    "type": "class",
    "title": "A",
    "children": [
      {
        "id": "df0a218d-7a08-4295-abb7-e0bdfb835414",
        "type": "color",
        "title": "red",
        "children": [
          {
            "id": "7c451766-5f91-48f5-8db5-868e7cc95905",
            "type": "taste",
            "title": "sour",
            "children": [
              {
                "id": "2567b1f1-2662-48fd-a487-167e514ce5d8",
                "type": "size",
                "title": "tiny"
              },
              {
                "id": "29a73327-d5be-44cc-8c1d-e45ddb8be2b7",
                "type": "size",
                "title": "small"
              },
              {
                "id": "718d54cf-ce19-44e9-9a94-3214ef482dc2",
                "type": "size",
                "title": "medium"
              },
              {
                "id": "f1f81f3a-be49-411d-b176-0d1e67f18864",
                "type": "size",
                "title": "large"
              },
              {
                "id": "ccbe91ef-7dec-4dc7-bbf5-ef79161670df",
                "type": "size",
                "title": "huge"
              }
            ]
          },
          {
            "id": "7b9ae76c-d189-4b44-9ea1-ea38b05d35ae",
            "type": "taste",
            "title": "bitter",
            "children": [
              {
                "id": "42b7f578-e907-475d-beb3-d1d53af1bec9",
                "type": "size",
                "title": "tiny"
              },
              {
                "id": "acaed672-d5df-43a2-9e30-5cf55f74b1ce",
                "type": "size",
                "title": "small"
              },
              {
                "id": "d4785d0b-9116-4361-8349-505934ceb9c9",
                "type": "size",
                "title": "medium"
              },
              {
                "id": "7ee5494f-dc36-45e2-bc09-2ac948133523",
                "type": "size",
                "title": "large"
              },
              {
                "id": "0ded484b-78f2-497e-bdfe-c9bd2ba78368",
                "type": "size",
                "title": "huge"
              }
            ]
          },
}

1 Answers1

0

if JSON is valid, you can easily get all the values you want via Creating POJO, this you can generate via POJO generator tools. you dont even need to parse JSON. just map JSON to Java POJO classes via GSON library and use it.

POJO generator -> http://www.jsonschema2pojo.org/

Jay Dangar
  • 3,271
  • 1
  • 16
  • 35