简体   繁体   中英

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

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

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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