相关文章推荐
有胆有识的鼠标垫  ·  (gdb) break ...·  5 月前    · 
从未表白的眼镜  ·  name 'device' is not ...·  7 月前    · 
一直单身的海豚  ·  qstringlist 查找-掘金·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

I am reading the below json content from a file and converting into a map but i am getting the below exception. Kindly let me know if anybody has come across such issue. I validated my json content and looks valid. Not sure why this error.

Json Content:

"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 input probably contains an invisible character on line 2, column 15. What happens if you try reading another input file that you've typed in by hand?
– dnault
                Aug 19, 2016 at 20:39
                Character code 160 is a non-breaking space which according to RFC 4627 is not valid JSON whitespace.
– Matthias Wiehl
                Aug 19, 2016 at 21:53
                Thanks !! It worked after typing the content. I believe some space was there while copy pasting
– user2334926
                Aug 22, 2016 at 17:21
                This can happen if you send a HTTP request as application/txt instead of application/json
– djangofan
                Apr 25 at 18:19

Google for Json formatter then click on any one of the option , Paste your json code in that formatter , it will validate & highlight the unwanted characters just delete them or replace then with what you want.

e.g. goto https://jsonformatter.org/ & follow the above steps

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.