python 将字符串中的unicode字符码转换成字符

将字符串str =’\u98ce\u534e\u7684\u51b2\u950b'转换成汉字显示

可以直接print输出

print u'\u98ce\u534e\u7684\u51b2\u950b'

但是这样在处理json文件中的编码就比较麻烦,可以将整串字符串转化:

    s = str.encode('latin-1').decode('unicode_escape')

猜你喜欢

转载自www.cnblogs.com/michealLang/p/9338548.html