我有一個 JSON 文件,其中包含許多對象和數組以及數組中的對象。我在 json 路徑中可訪問的路由對象中有源和目的地之間的路由列表 - data.offer.travels[1].routes。有 15 個這樣的路線對象。在每個路線對象中都有一個名為 legs 的數組,其長度可以是 1、2 或 3。我已經編寫了帶有 for 循環的方法以在路線對象內循環并返回只有一條路線的第一個路線索引。但它給出了一個錯誤。寫了一個for循環來做到這一點。這是代碼public JSONObject PrepareProvBookingRequestBody() throws IOException, ParseException { File jsonExample = new File(System.getProperty("user.dir"),"\\JSONOutputFiles\\ThreeAdults_TwoCh_StdRet_PUB\\ThreeAdults_TwoCh_StdRet_PUB_JS.json"); JsonPath jsonPath = new JsonPath(jsonExample); int routeindexOutbound=0; int routeindexInbound=0; List<Object> routesOutbound = jsonPath.getList("data.offer.travels[1].routes"); int NoOfOutboundRoutes= routesOutbound.size(); for (int i=0; i<NoOfOutboundRoutes; i++) { JsonArray legs = jsonPath.get("data.offer.travels[1].routes[i].legs"); int NoOfLegs = legs.size(); if (NoOfLegs==1) { routeindexOutbound=i; break; } }String DepartureDate = jsonPath.getString("data.offer.travels[1].routes[routeindexOutbound].legs[0].service_schedule_date");這是我得到的錯誤java.lang.IllegalArgumentException: The parameter "i" was used but not defined. Define parameters using the JsonPath.params(...) function有人可以建議我哪里出錯了嗎?
添加回答
舉報
0/150
提交
取消