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

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

使用 jsonpath 解析數組索引

使用 jsonpath 解析數組索引

慕斯709654 2023-03-31 17:06:40
我有一個 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有人可以建議我哪里出錯了嗎?
查看完整描述

1 回答

?
幕布斯6054654

TA貢獻1876條經驗 獲得超7個贊

您需要使用?帶有更多示例的jsonPath.param("i",i).get ...?


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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