使用动态对象名称解析JSON

时间:2018-08-16 12:22:43

标签: java json parsing jackson

我正在尝试从Fantasy Football API中解析一些数据以进行一些分析。

它返回一个称为“元素”的对象,我不太确定如何设置“对象”和“杰克逊”注释,因此映射器可以正确拾取它。我是否为每个不同的子对象都要求一个对象,即使它们的名称不同?

JSON示例:

   {
  "elements": {
    "1": {
      "explain": [
        [
          [
            {
              "name": "Minutes played",
              "points": 2,
              "value": 90,
              "stat": "minutes"
            },
            {
              "name": "Goals conceded",
              "points": -1,
              "value": 2,
              "stat": "goals_conceded"
            },
            {
              "name": "Saves",
              "points": 2,
              "value": 6,
              "stat": "saves"
            }
          ],
          1
        ]
      ],
      "stats": {
        "minutes": 90,
        "goals_scored": 0,
        "assists": 0,
        "clean_sheets": 0,
        "goals_conceded": 2,
        "own_goals": 0,
        "penalties_saved": 0,
        "penalties_missed": 0,
        "yellow_cards": 0,
        "red_cards": 0,
        "saves": 6,
        "bonus": 0,
        "bps": 24,
        "influence": 47,
        "creativity": 0,
        "threat": 0,
        "ict_index": 4.7,
        "total_points": 3,
        "in_dreamteam": false
      }
    },
    "2": {
      "explain": [
        [
          [
            {
              "name": "Minutes played",
              "points": 0,
              "value": 0,
              "stat": "minutes"
            }
          ],
          1
        ]
      ],
      "stats": {
        "minutes": 0,
        "goals_scored": 0,
        "assists": 0,
        "clean_sheets": 0,
        "goals_conceded": 0,
        "own_goals": 0,
        "penalties_saved": 0,
        "penalties_missed": 0,
        "yellow_cards": 0,
        "red_cards": 0,
        "saves": 0,
        "bonus": 0,
        "bps": 0,
        "influence": 0,
        "creativity": 0,
        "threat": 0,
        "ict_index": 0,
        "total_points": 0,
        "in_dreamteam": false
          }
        }
      }
    }

0 个答案:

没有答案