【问题标题】:How to decode Unicode escape sequence emojis encoded as \uXXXX?如何解码编码为\uXXXX的Unicode转义序列表情符号?
【发布时间】:2021-06-01 04:07:44
【问题描述】:

我正在尝试使用python对我下载的Instagram数据进行排序,数据是一个json文件,但是表情符号和其他非文本字符以我不理解的方式编码,例如:

json 文件将包含: \u00e2\u009c\u008c\u00f0\u009f\u0096\u00a4\u00f0\u009f\u008d\u0095\u00f0\u009f\u008e\u00b6\u00f0\u009f\u00a4\u00af。 在 Instagram 应用程序上显示: ✌????????????????

或 json:\u00e2\u0080\u0099。 Instagram:'(撇号)

我尝试使用u"string" 并发现了类似的问题hereherehere,但没有一个问题在python 中或向我提供任何有用的细节。

【问题讨论】:

    标签: python json instagram emoji python-unicode


    【解决方案1】:

    试试

    print(('\u00e2\u009c\u008c\u00f0\u009f\u0096\u00a4\u00f0\u009f\u008d\u0095\u00f0\u009f\u008e\u00b6\u00f0\u009f\u00a4\u00af'.encode('latin-1').decode('utf-8')))
    

    输出:

    ✌????
    

    【讨论】:

    • 您好,我正在尝试将该文本写入文件,但出现错误:UnicodeEncodeError: 'charmap' codec can't encode characters in position 12-14: character maps to <undefined>。我该如何解决这个问题?
    • @HaykPetrosyan 这能回答你的问题吗? stackoverflow.com/questions/27092833/…
    • 有点,我后来才发现 Instagram 和 Twitter 文本的编码是 latin-1 什么的。所以我们必须首先解码,然后编码为 utf-8 并做任何事情。
    • @Ani 为此 +1。你能分享一下来源或你是如何找到它的吗?
    【解决方案2】:

    如果您在 Windows 上,请按 win + 。 您将收到带有表情符号的提示 然后做 print("?") 输出: ?

    【讨论】:

      猜你喜欢
      • 2012-02-14
      • 2016-08-21
      • 2011-02-09
      • 2017-10-28
      • 1970-01-01
      • 2023-03-29
      • 2021-06-15
      • 1970-01-01
      • 2018-07-03
      相关资源
      最近更新 更多