在python中解码unicode字符串

2024-06-10 22:45:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我想解码以下字符串:

电话\u028c\u02c8m\u0251\u0279o\u028a\u032f

它应该是来自http://rhymebrain.com/talk?function=getWordInfo&word=tomorrow的JSON字符串中给定的“明天”的IPA

我的理解是应该是:

x = 't\u028c\u02c8m\u0251\u0279o\u028a\u032f'
print x.decode()

我尝试过hereherehere,和here(以及其他一些或多或少适用的解决方案),以及对其各部分的几种置换,但我无法使其发挥作用。在

谢谢你


Tags: 字符串comhttpherefunction解码talk电话
1条回答
网友
1楼 · 发布于 2024-06-10 22:45:31

在您的字符串(在Python 2.x中,您似乎正在使用)前面需要一个u来表示这是一个unicode字符串:

>>> x = u't\u028c\u02c8m\u0251\u0279o\u028a\u032f'  # note the u
>>> print x
tʌˈmɑɹoʊ̯

如果已将字符串存储在变量中,则可以使用以下构造函数将字符串转换为unicode:

^{pr2}$

相关问题 更多 >