2

I have created datatables and my input JSON is in the below format.

[{"input" : "안녕하세요"}]

Since the string is in Korean language, data table is not able to load this data. Getting below error... Data tables warning..Requested unknown parameter...

Have tried setting content="text/html;charset=utf-8" in my main html page. Nothing has worked... Please let me know how to resolve this. Thanks.

Monica
  • 21
  • 4
  • This might be of interest: http://stackoverflow.com/questions/3995559/json-character-encoding It suggests that the data coming back from the server isn't returned as unicode...? Datatables has no issue displaying the characters within a standard table: https://jsfiddle.net/annoyingmouse/4644q44s/ – annoyingmouse Jan 18 '16 at 13:00

1 Answers1

0

For java you can encode it like:

@ResponseBody
    @RequestMapping(value = "/searchFilter.do")
    public ResponseEntity<String> getContactSearchBean(HttpServletRequest request, HttpServletResponse response,
            String clientName) {
        logger.info("Getting data  according to search filter to refresh table ");
        List<Map<String, Object>> contactDetails = service.getContactDetailSearch(request, clientName);
        JSONArray json = JSONArray.fromObject(contactDetails);
        String jsonString = json.toString();
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.add("Content-Type", "text/html; charset=utf-8");
        logger.info("returning data for populating datatable");
        return new ResponseEntity<>(jsonString, responseHeaders, HttpStatus.OK);
    }
Suraj Kumar
  • 5,547
  • 8
  • 20
  • 42
  • For other languages too you should set charset=utf-8 in responseHeaders – Abhinandan Kumar Mar 01 '19 at 08:38
  • Can you please also add a little description for less informed people like me. – Mohit Jain Mar 01 '19 at 08:52
  • UTF-8 encoding supports chinese or special character. – Abhinandan Kumar Mar 15 '19 at 08:42
  • So if you want to display chinese characters in your datatable then you will have to encode your data in UTF-8 like this HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "text/html; charset=utf-8"); This code will encode your response as UTF-8 in java. If you are using any other lenguage then also you should encode your response with utf-8 encoding – Abhinandan Kumar Mar 15 '19 at 08:46