java如何循环json并在上下文中发布每个索引
假设我有以下内容:
<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>
# 1 楼答案
这可以通过拆分原始消息来完成