JSON character encoding

后端 未结 10 1010
春和景丽
春和景丽 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 15:05

    First, your posted data isn't valid JSON. This would be:

    {"value": "aériennes"}
    

    Note the double quotes: They are required.

    The Content-Type for JSON data should be application/json. The actual JSON data (what we have above) should be encoded using UTF-8, UTF-16, or UTF-32 - I'd recommend using UTF-8.

    You can use a tool like Wireshark to monitor network traffic and see how the data looks, you should see the bytes c3 89 for the é. I've never worked with Spring, but if it's doing the JSON encoding, this is probably taken care of properly, for you.

    Once the JSON reaches the browser, it should good, if it is valid. However, how are you inserting the data from the JSON response into the webpage?

提交回复
热议问题