简体   繁体   English

com.fasterxml.jackson.core.JsonParseException:读取json文件时出现意外字符(代码160)

[英]com.fasterxml.jackson.core.JsonParseException: Unexpected character(code 160) while reading the json file

I am reading the below json content from a file and converting into a map but i am getting the below exception. 我正在从文件中读取以下json内容并转换为地图,但我得到以下异常。 Kindly let me know if anybody has come across such issue. 如果有人遇到过这样的问题,请告诉我。 I validated my json content and looks valid. 我验证了我的json内容并且看起来有效。 Not sure why this error. 不知道为什么这个错误。

Json Content: Json内容:

{
    "Results":[{         
        "TotalPositiveFeedbackCount": 0      
    },{
        "TotalPositiveFeedbackCount": 1      
    }   ]
}

Code: 码:

Map<String, Object> domainMap = new HashMap<String, Object>();
try {
    responseJson = getFile("reviewresponse.json");
    //responseJson = new String(Files.readAllBytes(Paths.get("reviewresponse.json")), StandardCharsets.UTF_8);
    ObjectMapper jsonObjectMapper = new ObjectMapper();
    jsonObjectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    domainMap = jsonObjectMapper.readValue(responseJson,
                   new TypeReference<Map<String, Object>>() {});
} 

Exception Details: 例外细节:

com.fasterxml.jackson.core.JsonParseException: Unexpected character (' ' (code 160)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name
 at [Source: {
    "Results":[{         
        "TotalPositiveFeedbackCount": 0      
    },{
        "TotalPositiveFeedbackCount": 1      
    }   ]
}
; line: 2, column: 15]

Your JSON content contains non-breaking spaces (character code 160, commonly known as &nbsp; ) likely from copying and pasting JSON (usually from a webpage) that used &nbsp; 您的JSON内容包含可能通过复制和粘贴使用了&nbsp; JSON(通常来自网页)的不间断空格(字符代码160,通常称为&nbsp; to indent the JSON. 缩进JSON。

在此输入图像描述

You can fix it with 你可以修复它

responseJson = responseJson.replace('\u00A0',' ');

暂无
暂无

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

相关问题 com.fasterxml.jackson.core.JsonParseException:意外的字符 - com.fasterxml.jackson.core.JsonParseException: Unexpected character Riak&Java - com.fasterxml.jackson.core.JsonParseException:意外的字符(&#39;&lt;&#39;(代码60)) - Riak & Java - com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)) RestTemplate::exchange() - com.fasterxml.jackson.core.JsonParseException:意外字符('&lt;'(代码 60)) - RestTemplate::exchange() - com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)) com.fasterxml.jackson.core.JsonParseException:意外的字符(&#39;\\&#39;(代码92))[Java] - com.fasterxml.jackson.core.JsonParseException: Unexpected character ('\' (code 92)) [Java] Google Http客户端库Java:com.fasterxml.jackson.core.JsonParseException:意外字符(“ G” - Google Http Client Library java: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('G' com.fasterxml.jackson.core.JsonParseException是否为* .json.swp? - com.fasterxml.jackson.core.JsonParseException for *.json.swp? 找不到com.fasterxml.jackson.core.JsonParseException的类文件 - class file for com.fasterxml.jackson.core.JsonParseException not found com.fasterxml.jackson.core.JsonParseException:无法识别的字符转义符&#39;U&#39;(代码85) - com.fasterxml.jackson.core.JsonParseException: Unrecognized character escape 'U' (code 85) 如何使无法识别的字符转义 &#39;.&#39; (代码 46)被识别 - com.fasterxml.jackson.core.JsonParseException - How to make Unrecognized character escape '.' (code 46) to be Recognized - com.fasterxml.jackson.core.JsonParseException 错误 com.fasterxml.jackson.core.JsonParseException:无法识别的令牌 - Error com.fasterxml.jackson.core.JsonParseException: Unrecognized token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM