简体   繁体   English

在 express 服务器中以 UTF-16 编码发送 JSON 响应

[英]Send a JSON response in UTF-16 encoding in express server

I have a client which is reading the response from my server in UTF-16, so my normal JSON appears to be something written in chinese like this我有一个客户端正在以 UTF-16 格式从我的服务器读取响应,所以我的普通 JSON 似乎是这样用中文写的

≻畳捣獥≳琺畲ⱥ琢歯湥㨢攢䩹扨捇佩䩩啉䥺丱䥩䥳剮挵䥃䤶火噘䩃⸹祥灊䍚㙉橉歖䝍㉉㉙楖穎楎坍桊橍ぁ積睫㉎橖楙獉浉礹㉚畆塡桰䝤癬止歬橉楯坎睑橙橚坚㍉㉍硉浙祅䑍穑呏㍁坚橎楉楷坡う橉硯呎す呏㑉䑎祑䍌汊䡥楁橏ㅅ橎㕑積祫䑎㥊種乂歓奆洹睨啙䍤䉰㕈奡娸䉁䍡㉈䥐湘湚獢橦噳䅆Ⱒ產敳≲笺瀢潲楦敬㨢≻畦汬慎敭㨢䄢歮瑩倠牡獡慨≲ⱽ椢楮楴污敓畴≰昺污敳∬潲敬㨢唢䕓≒∬敶楲楦摥㨢牴敵∬捡楴敶㨢牴敵∬楟≤∺搵戰挶扥㌷ㅢ慢〲㌴〹攷扣Ⱒ攢慭汩㨢愢歮瑩歀畯瑮椮≮∬牯慧楮慺楴湯㨢䬢畯瑮䈠≉∬敶楲楦慣楴湯潔敫≮∺㡣敦㙣㍥ㄷ㈳っ㌹搹㤷㔴愱愸㔵搰敥Ⱒ挢敲瑡摥瑁㨢㈢㄰ⴹ㘰㈭吰ㄱ㈺㨴㜲㌮ㄴ≚∬灵慤整䅤≴∺〲㤱〭ⴸ㐰ㅔ㨲㄰ㄺ⸴㔳娸Ⱒ弢癟㨢ⰰ漢杲湡穩瑡潩䥮≤∺搵戰挶扥㌷ㅢ慢〲㌴〹攷捣索}

but response is something like this:但回应是这样的:

{
    "success": true,
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjZmJjYmI0NmQ2MjNjMmQ4YmUyY2IxNyIsIm9yZ2FuaXphdGlvbklkIjoiNWNmYmNiYjU2ZDYyM2MyZDhiZTJjYjE4IiwiaWF0IjoxNTY1MzM3NTcxLCJleHAiOjE1NjUzNDgzNzF9.HEfSjX2TjgyI9oL2f6-ECgABfuJz2vQDwHvR5MGg_aU",
    "user": {
        "profile": {
            "fullName": "Ankit"
        },
        "initialSetup": false,
        "role": "USER",
        "verified": true,
        "active": true,
        "_id": "5cfbcbb46d623c2d8be2cb17",
        "email": "abc@xyz.com",
        "organization": "ABC",
        "createdAt": "2019-06-08T14:52:36.849Z",
        "updatedAt": "2019-07-29T07:14:58.130Z",
        "__v": 0,
        "organizationId": "5cfbcbb56d623c2d8be2cb18"
    }
}

I want to know if there is a way I can send the response, so the client can also read it as JSON above, and not as chinese characters.我想知道是否有一种方法可以发送响应,因此客户端也可以将其读取为上面的 JSON,而不是中文字符。

Make sure that your server sends the correct HTTP header for json data ( Content-type: application/json ) and encodes the data either as utf-8, which is the default encoding for this content type, or sends an Encoding: header that contains the character encoding used.确保您的服务器为 json 数据发送正确的 HTTP 标头 ( Content-type: application/json ) 并将数据编码为 utf-8,这是此内容类型的默认编码,或者发送一个Encoding:标头,其中包含使用的字符编码。

If the client is unable to interpret this correctly, it's their fault.如果客户无法正确解释这一点,那是他们的错。 You can't seriously be expected to work around faulty client implementations at the server side.不能认真地期望您在服务器端解决错误的客户端实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM