我有一个包含 json 格式的 HashMap 客户列表的文件。
像这样:
{"Davide":{"name":"Davide","cf":"FRCDVD","pi":"1234",
"telephone":"333","website":"www","sector":"Student","address":"Rome"}}
这只是列表中的一个客户。 每次调用 Controller 时,我都想从文件中获取数据并将它们转换为 HashMap 列表。
我试着这样做:
HashMap<String, Customer> listCustomer = new HashMap<>();
listCustomer = new ObjectMapper().readValue(pathCustomerFile, HashMap.class); //This line gives me error
我遇到了这个错误:
org.codehaus.jackson.JsonParseException: Unexpected character ('/' (code 47)): maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)
我该怎么做?
最佳答案
我最近遇到了这个问题。我试图将路径(以字符串的形式)传递给 readValue。您需要将要解析的字符串或文件对象传递给它。根据您的变量名,我认为您可能已将文件路径传递给它。
(基本上,它读取文件路径中的“/”并在其上抛出错误。
关于java - org.codehaus.jackson.JsonParseException : Unexpected character ('/' (code 47)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30799635/