【问题标题】:Can't find syntax to split JSON array in Apache Camel using jsonpath找不到使用 jsonpath 在 Apache Camel 中拆分 JSON 数组的语法
【发布时间】:2022-01-22 07:14:37
【问题描述】:

我有一个传入的字符串,它是一个 JSON 数组,并且想要处理数组中的每个元素。该数组包含对象,例如[{ "title": "book 1"}, { "title": "book 2"}]

代码如下:

        // code that returned string here...
        .log("body: ${body}") // got JSON string
        .marshal().json(JsonLibrary.Jackson)

    // .split().jsonpath("$") entire array
    // .split().jsonpath("$.") blows up
    // .split().jsonpath("$[]") blows up
    // .split().jsonpath("$.[]") blows up
    // .split().jsonpath("$.[*]") fail

        .split().jsonpath("what do I put here?") // how to pass each bit of the array?

        .to("direct:book");

    from("direct:book")
        .log("book ${body}") 
    ;
    

如何一一处理数组的每个元素?

【问题讨论】:

标签: apache-camel jsonpath


【解决方案1】:

先拆分数组,然后执行json路径

    .log("body: ${body}") 
            .split().body()
            .marshal().json(JsonLibrary.Jackson)
       // you have n items in there 
        // setProperty("name",jsonpath("$.name")) 
.end();  

    
 

【讨论】:

  • 感谢您的观看,但我认为我们都只是在浪费时间使用 jsonpath。以上将所有逗号上的内容分开。我用示例数据更新了问题。
猜你喜欢
  • 2017-04-14
  • 2018-05-27
  • 2018-12-10
  • 1970-01-01
  • 2022-08-19
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多