我使用JsonPathExpression拆分了JSONArray,但结果删除了每个JSON中的每个双引号,这是我的RouteBuilder。
from("timer:scheduler?repeatCount=1")
.to("http:localhost:8901/rest/getData")
.split(new JsonPathExpression("$.[*]"))
.process(new Processor() {
@java.lang.Override
public void process(Exchange exchange) throws Exception {
String input = exchange.getIn().getBody(String.class);
exchange.getIn().setBody(input);
}
})
.unmarshal().json(JsonLibrary.Jackson, Map.class)
.log("${body}");
我只是想用杰克逊解组那些JSON,但正如你可能知道的那样,杰克逊不会在没有双引号的情况下解析那些JSON,是的,我可能会允许杰克逊在没有双引号的情况下进行解析,但我更喜欢JSON来拥有它。它还会将:
更改为=
。
REST调用的响应是这样的。
[
{
"v_KDKANWIL": null,
"v_GJJ": "CRJ"
},
{
"v_KDKANWIL": "002",
"v_GJJ": "CRJ"
}
]
分割和处理后,它就像这样(只是第一个JSON)。
{
v_KDKANWIL=null,
v_GJJ=CRJ
}
我怀疑不只是分裂,而且还在处理器中,因为我使用String类型设置了新的主体。
提前致谢。
修改
啊,傻我,它不应该是String而是Map,所以这个。
String input = exchange.getIn().getBody(String.class);
成为这个。
Map input = exchange.getIn().getBody(String.class);
答案 0 :(得分:0)
`.split()` splits data into java.util.map. Marshal data after split to convert it to JSON using Jackson or Gson. I faced the same issue and adding `marshal()` resolved the issue.
.marshal().json(JsonLibrary.Jackson)