tkf / emacs-request

Request.el -- Easy HTTP request for Emacs Lisp
http://tkf.github.com/emacs-request/
GNU General Public License v3.0
629 stars 93 forks source link

Is it support response contains utf-8 characters ? #88

Closed oaksharks closed 6 years ago

oaksharks commented 6 years ago

I have received the response with some chinese characters , but they are shown as numbers like

 {"weatherinfo":{"city":"\345\214\227\344\272\254"}}

Is there any suggestions ?

davidshepherd7 commented 6 years ago

Hi, I just ran into this problem and the solution was to encode the string as 'utf-8 after doing the json encode (and I guess you would do something similar for decoding if you need to decode).

Here's the patch for my use-case: https://github.com/davidshepherd7/anki-mode/commit/e052de184fb8eff9d382fb0d0dbb267777662f7f (I also switched to using a threading macro in the same commit, I hope it's still clear what the change was).

I got the idea from syohex's response to this issue, so that might be helpful too.

oaksharks commented 6 years ago

@davidshepherd7 Thanks for your reply . Just as your said I try to encode the response string:

(encode-coding-string response-json-data 'utf-8)

but it does not works then I tried the decode function:

(decode-coding-string response-json-data 'utf-8)

I just got the right result . but I do not understand why the name of this function is decode-coding-string .

davidshepherd7 commented 6 years ago

I'm not really sure, but I think it's because it "decodes" a string which is coded in some non-emacs-native system (e.g. utf8) into emacs' native system.

oaksharks commented 6 years ago

I got that , it's already encoded in uft-8 but emacs just can not recognize that , so decode data by using utf-8 to bytes(or other thing) . Thanks again .