vivoapex

新手求问:后台接口返回 UTF-8 的数据, js 怎么处理的??

  •  
  •   vivoapex · Dec 9, 2018 · 3456 views
    This topic created in 2718 days ago, the information mentioned may be changed or developed.

    我是搞 android 的,近来在看 js 相关书籍,有个疑问. es6 中字符串编码是 utf-16 格式,如果请求一个后台接口,接口返回的是 utf-8 格式的 json, 拿到数据是要自己转码吗? 还是定借口的时候就和后台商量好给前端只返回 utf-8 格式数据??

    新手不太明白实际开发怎么处理的...希望各位大佬解答

    3 replies    2018-12-14 11:11:05 +08:00
    orancho
        1
    orancho  
       Dec 10, 2018 via iPhone
    UTF-16 是 JavaScript 的字符串实现所用的编码,和传输所用的编码无关。现代的 Web 应用一般默认用 UTF-8 进行编码被传输的数据,大部分情况下浏览器会正确解码,你也可以在 HTTP header 中指定 body 的文本编码。

    https://www.w3.org/International/articles/http-charset/index.en.html
    yimity
        2
    yimity  
       Dec 10, 2018 via Android
    你试一下就知道了。
    yangehappy
        3
    yangehappy  
       Dec 14, 2018
    实际开发中不用关注这个问题
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3009 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 12:24 · PVG 20:24 · LAX 05:24 · JFK 08:24
    ♥ Do have faith in what you're doing.