Convert a Unicode string to a string in Python (containing extra symbols)

前端 未结 10 2674
夕颜
夕颜 2020-11-22 01:20

How do you convert a Unicode string (containing extra characters like £ $, etc.) into a Python string?

10条回答
  •  一生所求
    2020-11-22 02:11

    file contain unicode-esaped string

    \"message\": \"\\u0410\\u0432\\u0442\\u043e\\u0437\\u0430\\u0446\\u0438\\u044f .....\",
    

    for me

     f = open("56ad62-json.log", encoding="utf-8")
     qq=f.readline() 
    
     print(qq)                          
     {"log":\"message\": \"\\u0410\\u0432\\u0442\\u043e\\u0440\\u0438\\u0437\\u0430\\u0446\\u0438\\u044f \\u043f\\u043e\\u043b\\u044c\\u0437\\u043e\\u0432\\u0430\\u0442\\u0435\\u043b\\u044f\"}
    
    (qq.encode().decode("unicode-escape").encode().decode("unicode-escape")) 
    # '{"log":"message": "Авторизация пользователя"}\n'
    

提交回复
热议问题