[英]Extract values from a json response in mule flow
I have a json response like this -- I want to extract the value of p_ProviderID. 我有一个这样的json响应-我想提取p_ProviderID的值。 Please guide me how to do it in a mule flow?
请指导我如何在ule子流中进行操作?
{ "category" : "Address", "status": "SUCCESS", "result": { "p_ProviderID": 4, "p_NewProvInd": "Exist" } }
Use <json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object" />
and then you can get the value using MEL #[message.payload.result.p_ProviderID]
使用
<json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object" />
,然后可以使用MEL #[message.payload.result.p_ProviderID]
获取值
For example, you can get the value of p_ProviderID in logger after using <json:json-to-object-transformer/>
as follow:- 例如,使用
<json:json-to-object-transformer/>
如下所示,您可以在记录器中获取p_ProviderID的值:-
<json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object" />
<logger message="#[message.payload.result.p_ProviderID]" level="INFO" doc:name="Logger"/>
For a Json as simple as this, you are better off with JsonPath. 对于如此简单的Json,最好使用JsonPath。 A simple expression like this
#[json:result/p_ProviderID]
would give you what you wanted. 像这样的简单表达式
#[json:result/p_ProviderID]
将为您提供所需的内容。
PS: Mule's support for JsonPath as of 3.5 is quite limited and is not as flexible as Xpath. PS:从3.5版本开始,Mule对JsonPath的支持非常有限,并且不如Xpath灵活。
We need to use Json to Object converter and set return class type to java.util.Map or Java.util.List - in your case this is Map. 我们需要使用Json to Object转换器,并将返回类类型设置为java.util.Map或Java.util.List-在您的情况下,这是Map。 If you have multiple element of same type in Json you need to use java.util.List
如果Json中有多个相同类型的元素,则需要使用java.util.List
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.