如何使用mule读取json文件?
我的源代码中有以下部分:如何使用mule读取json文件?,json,mule,esb,Json,Mule,Esb,我的源代码中有以下部分: <file:inbound-endpoint connector-ref="fileConnector" path="C:/tmp/input" encoding="UTF-8" mimeType="application/json"> <file:filename-wildcard-filter pattern="*.json"/> </file:inbound-endpoint> <json:json-to-
<file:inbound-endpoint connector-ref="fileConnector" path="C:/tmp/input" encoding="UTF-8" mimeType="application/json">
<file:filename-wildcard-filter pattern="*.json"/>
</file:inbound-endpoint>
<json:json-to-object-transformer returnClass="java.util.HashMap"/>
<logger level="INFO" message="#[message.payload]"/>
一切都很好!但在执行时抛出下一个异常:“消息:未能从“json”转换为“java.util.HashMap”代码:MULE-ERROR-109”
有人能帮我解决这个错误吗?流程如下:
`
错误在JSON文件中。人物
编码不正确,因此我产生了错误
尝试通过
使用
我定义为encoding=“UTF-8”的属性
解决方案
将JSON文件的字符编码更改为“UTF-8”
知识库:
如果异常堆栈为:
消息:无法从“json”转换为“java.util.HashMap”代码:
MULE_错误-109
异常堆栈是:
你的JSON有效载荷是什么??你想在日志中打印有效载荷还是想从中提取元素值?我正在调试我的流,有效载荷的内容是一个字节[]数组。如何将此数组转换为JSON文件?我将字节数组放入object,将object放入JSON,现在我有了一个类似于“param:\r\n”的文件内容字符串{\r\n\t\t\t[\r\n\t\t\t\t\“key\”:“1\”]……..。如何在我的负载中选择“key”的值?你的Json内容是什么?你想在日志中打印什么..整个Json或任何特定的Json值?这看起来不像是有效的Json,这可能就是你不能使用
Json到对象转换器的原因。
<file:inbound-endpoint
connector-ref="fileConnector" path="C:/tmp/input"
doc:name="File Input" responseTimeout="10000"
encoding="UTF-8" mimeType="text/plain">
<file:filename-wildcard-filter pattern="*.json"/>
</file:inbound-endpoint>
<json:json-to-object-transformer returnClass="java.util.HashMap"doc:name="JSON to Object"/>`