JSON character encoding

后端 未结 10 995
春和景丽
春和景丽 2020-11-27 14:14

My Java web application submits an AJAX request that returns JSON such:

{\'value\': \'aériennes\'}

When \'aériennes\' is displayed in the w

10条回答
  •  自闭症患者
    2020-11-27 14:55

    The answers here helped me solve my problem, although it's not completely related. I use the javax.ws.rs API and the @Produces and @Consumes annotations and had this same problem - the JSON I was returning in the webservice was not in UTF-8. I solved it with the following annotations on top of my controller functions :

    @Produces(javax.ws.rs.core.MediaType.APPLICATION_JSON + "; charset=UTF-8")
    

    and

    @Consumes(javax.ws.rs.core.MediaType.APPLICATION_JSON + "; charset=UTF-8")
    

    On every endpoint's get and post function. I wasn't setting the charset and this solved it. This is part of jersey so maybe you'll have to add a maven dependency.

提交回复
热议问题