我有一个json但不知道如何解析它

时间:2018-12-06 05:44:53

标签: android parsing

该数组有一个名为children的字符串,在该子字符串中可以有另一个子字符串,在该子字符串中又可以是另一个子字符串。请帮助我解析该字符串 json的格式是这样的 我有一个json响应,其中有array的array内部。我想获取给定标签的所有值。

{
    "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 个答案:

答案 0 :(得分:0)

如果JSON有效,则可以通过创建POJO轻松获得所需的所有值,可以通过POJO生成器工具生成该值。您甚至不需要解析JSON。只需通过GSON库将JSON映射到Java POJO类并使用它即可。

POJO生成器-> http://www.jsonschema2pojo.org/