首页 > 解决方案 > 如何转换列表从 vertx 到 String Array 以用于笛卡尔积

问题描述

我有一个应该从 json 文件访问数据的方法,基本上是一个如下所示的 api,该方法访问了www.my-work.com的 API ,接下来我访问了参数(getConfig 方法返回一个 JsonObject)。

我想做的事?首先,将参数转换为 String [],然后使用 guava 制作笛卡尔积,然后将 String 附加到

String apiUrl = operator.getConfig().getString("api");

我的方法是,

public  ParserService runParserTask(String tourOperator, Handler<AsyncResult<Void>> handler) {
                TourOperator operator = TourOperatorFactory.getOperator(tourOperator, vertx, config);
                String apiUrl = operator.getConfig().getString("api");

            operator.getConfig().getJsonArray("parameters").stream().map(o -> {
                List<JsonArray> parameters = ((JsonObject)o).getJsonObject("queryParameters").stream().map(e -> {
                    // TODO int's need to convert JsonArray to String[] and change parameters variable type
                    return (JsonArray)e.getValue();
                }).collect(Collectors.toList());


                // TODO further we'll compact all parameters variants (let's use guava cartesian lib,
                // TODO do not forget to add guava dependency to maven project) and call operator.fetchData(url)
                return null;
            });
            return null;
        }

为了更好地理解下面的 json 文件(已编辑且未完整)

"operators": {
    "tez" : {
      "api": "www.my-work.com/search/getResult",
      "parameters": [
        {
          "country": "London",
          "queryParameters": {
            "priceMin": ["0"],
            "priceMax":["150000"],
            "currency":["5561"],
          parameters should scroll at the same time 
            "hotelClassId":["4"],
            "accommodationId":["158525","9002884","1","14317","14357", 
               "282471","161160"],
            "rAndBId":["15350","2424","2474","2749","5737","5738"],
            "tourTypes": ["1","2","3","6"],
            "locale":["ru"],
            "cityId":["786"],
            "countryId":["147573"],

标签: javajsonapiparsingvert.x

解决方案


推荐阅读