假设我有以下CamelContext:
<camelContext id="camelId" xmlns="http://camel.apache.org/schema/spring">
<route id="upsertItem">
<from uri="cxf:bean:someEndpoint" />
<process ref="someTransformer" />
<log message="$someJson"/>
</route>
</camelContext>
$someJson 包含以下 json:
{
"0":{
"title":"hello world",
"description":"a greeting to the world"
},
"1":{
"title":"goodbye world",
"description":"a goodbye to the world"
}
//might have more indexes
}
我想编辑我的CamelContext,以便它可以将每个索引发布到端点。问题是我不知道如何迭代 JSON。
所以我想要看起来像这样的东西:
<loop src="${someJson[index]}">
<to uri="http://bookstore/api/books"/>
</loop>
最佳答案
可以通过拆分原始消息来完成
<split>
<jsonpath>$[*]</jsonpath>
<log message="${body}"/>
</split>
关于java - 如何循环 json 并将每个索引发布到camelcontext中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58658647/