亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

訪問要存儲在 AWS Dynamo 數據庫表中的嵌套 JSON 對象

訪問要存儲在 AWS Dynamo 數據庫表中的嵌套 JSON 對象

紅糖糍粑 2023-09-06 16:14:27
我希望訪問休息請求中的嵌套 JSON 對象,以將其存儲為 AWS 上的 Dynamo DB 表中的主鍵。Json 對象的格式如下:{ "api": {    "results": 543,    "fixtures": [      {        "fixture_id": 95095,        "venue": "Estádio Rei Pelé",        "goalsHomeTeam": 1,        "goalsAwayTeam": 1,        "awayTeam": {          "logo": "https://media.api-football.com/teams/156.png",          "team_id": 156,          "team_name": "Sao Bento"        },        "event_timestamp": 1569715200,        "referee": null,        "elapsed": 90,        "score": {          "halftime": "0-0",          "penalty": null,          "fulltime": "1-1",          "extratime": null        },        "round": "Regular Season - 25",        "event_date": "2019-09-29T00:00:00+00:00",        "statusShort": "FT",        "homeTeam": {          "logo": "https://media.api-football.com/teams/146.png",          "team_id": 146,          "team_name": "CRB"        },我正在嘗試使用以下代碼訪問它,但我NullPointerException在第 38 行上得到了一條信息,即以下開始的行int fixture_id。我的代碼如下:JsonParser parser = new JsonFactory().createParser(new File("fixturesTwo.json"));    JsonNode rootNode = new ObjectMapper().readTree(parser);    Iterator<JsonNode> iter = rootNode.iterator();    ObjectNode currentNode;    while (iter.hasNext()) {        currentNode = (ObjectNode) iter.next();        int fixture_id = currentNode.path("api").findPath("fixtures").findValue("fixture_id").asInt();        int league_id = currentNode.path("api").findPath("fixtures").findValue("league_id").asInt();我猜這與我正在做的事情類似,我只是不知道我做錯了什么。
查看完整描述

1 回答

?
料青山看我應如是

TA貢獻1772條經驗 獲得超8個贊

rootNode 有節點“API”。currentNode:


{

   "results":543,

   "fixtures":[

      {

         "fixture_id":95095,

         "venue":"Estádio Rei Pelé",

         "goalsHomeTeam":1,

         "goalsAwayTeam":1,

         "awayTeam":{

            "logo":"https://media.api-football.com/teams/156.png",

            "team_id":156,

            "team_name":"Sao Bento"

         },

         "event_timestamp":1569715200,

         "referee":null,

         "elapsed":90,

         "score":{

            "halftime":"0-0",

            "penalty":null,

            "fulltime":"1-1",

            "extratime":null

         },

         "round":"Regular Season - 25",

         "event_date":"2019-09-29T00:00:00+00:00",

         "statusShort":"FT",

         "homeTeam":{

            "logo":"https://media.api-football.com/teams/146.png",

            "team_id":146,

            "team_name":"CRB"

         }

      }

   ]

}

正確的代碼:


int fixture_id = currentNode.path("fixtures").findValue("fixture_id").asInt();


查看完整回答
反對 回復 2023-09-06
  • 1 回答
  • 0 關注
  • 102 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號