关于json格式python中文编码问题

当json格式包含中文字符时,总是出现 u"xxxxx" 的格式或者 "\xxx" 的字符编码,而非中文字符,那么如何转换成中文字符呢?

#-*- coding:utf-8 -*-
import json
word = "我喜欢你"
ss = []
ss.append(word)

#方法一, decode("raw_unicode_escape")
print json.dumps(ss).decode("raw_unicode_escape")
#方法二, ensure_ascii = False
print json.dumps(ss,ensure_ascii = False)

猜你喜欢

转载自blog.csdn.net/qq_32023541/article/details/80045858