简体   繁体   English

如何使用m子读取json文件?

[英]How read a json file with mule?

I have this section in my source code: 我的源代码中有此部分:

<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]"/>

everything compile fine! 一切编译正常! but at execute throws the next exception: "Message: failed to transform from "json" to "java.util.HashMap" Code: MULE-ERROR-109" 但是在执行时会引发下一个异常: “消息:无法从“ json”转换为“ java.util.HashMap”代码:MULE-ERROR-109”

Can anyone help me about this error? 有人可以帮我解决这个错误吗?

The flow was as follows: 流程如下:

 <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"/>` 

The error was in the JSON file. 错误出在JSON文件中。 The character encoding was not right and for this reason I was generating errors when trying to transform through <json: json-to-object-transformer returnClass = "java.util.HashMap" doc: name = "JSON to Object" / > after making reading the file with <file: inbound-endpoint> attribute where I had defined as encoding = "UTF-8" 字符编码不正确,因此,当尝试通过<json: json-to-object-transformer returnClass = "java.util.HashMap" doc: name = "JSON to Object" / >进行转换时,我生成了错误<json: json-to-object-transformer returnClass = "java.util.HashMap" doc: name = "JSON to Object" / >使用<file: inbound-endpoint>属性读取文件,其中我已将其定义为encoding =“ UTF-8”

Solution

Change the character encoding of the JSON file to "UTF-8" 将JSON文件的字符编码更改为“ UTF-8”

Knowledge Base: 知识库:

If the exception stack is: 如果异常堆栈为:

Message: Failed to transform from "json" to "java.util.HashMap" Code: MULE_ERROR-109 消息:未能从“ json”转换为“ java.util.HashMap”代码:MULE_ERROR-109


Exception stack is: 异常堆栈为:

  1. Unexpected character ((code 65279 / 0xFEFF) '?'): Expected to valid value (number, string, array, object, 'true', 'false' or 'null') at [Source: java.io.InputStreamReader@2fba237; 意外的字符((代码65279 / 0xFEFF)“?”):预期为有效值(数字,字符串,数组,对象,“真”,“假”或“空”),位于[来源:java.io.InputStreamReader@2fba237 ; line 1, column 2 (org.codehaus.jackson.JsonParseException) org.codehaus.jackson.JsonParser: 1433 (null) 第1行,第2列(org.codehaus.jackson.JsonParseException)org.codehaus.jackson.JsonParser:1433(空)
  2. Failed to transform from "json" to "java.util.HashMap (org.mule.api.transformer.TransformerException) org.mule.module.json.transformers.JsonToObject: 132 ( http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html ) 无法从“ json”转换为“ java.util.HashMap(org.mule.api.transformer.TransformerException)org.mule.module.json.transformers.JsonToObject:132( http://www.mulesoft.org/docs /site/current3/apidocs/org/mule/api/transformer/TransformerException.html

Consider change the character encoding of the JSON file 考虑更改JSON文件的字符编码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM