Emoji characters cannot be encoded to JSON

后端 未结 6 1847
长发绾君心
长发绾君心 2021-01-31 06:29

I have a UITextView which I call messageField. The data within that messageField is POST-ed to server in JSON format. When th

6条回答
  •  庸人自扰
    2021-01-31 06:41

    One thing to be aware of with Emoji - if your json encoder is set to produce ASCII output (i.e. using the \u<4 hex digits> character format), some Emoji characters will break because they use more than two bytes and thus don't fit in the 4 hex digits allowed.

    So in python for example, be sure to use:

    json.dumps(, ensure_ascii=False)
    
        

    提交回复
    热议问题