How To Decode Javascript Unicode String In Python?
I found that it is a character of TWO HEARTS here. I tried to decode it: a = '\ud83d\udc95' a.encode('utf-8').decode('utf-8') UnicodeEncodeError: 'utf-8' codec can't encode charact
Solution 1:
Use json module to help you solve different Unicode
.
import json
a = '\ud83d\udc95'
m = json.dumps({"k": a})
print(json.loads(m)["k"]) # 💕
Solution 2:
I cant make a comment, so here is the answer for how to transform"\uD83D\uDC95".encode('utf-16', 'surrogatepass').decode('utf-16').encode('unicode_escape').decode('utf-8')
Post a Comment for "How To Decode Javascript Unicode String In Python?"