我在Python中有一本字典词典:
d = {"a11y_firesafety.html":{"lang:hi": {"div1": "http://a11y.in/a11y/idea/a11y_firesafety.html:hi"}, "lang:kn": {"div1": "http://a11y.in/a11ypi/idea/a11y_firesafety.html:kn}}}
Run Code Online (Sandbox Code Playgroud)
我在JSON文件中有这个,我用它编码json.dumps().现在,当我使用json.loads()Python 解码它时,我得到一个这样的结果:
temp = {u'a11y_firesafety.html': {u'lang:hi': {u'div1': u'http://a11y.in/a11ypi/idea/a11y_firesafety.html:hi'}, u'lang:kn': {u'div1': u'http://a11y.in/a11ypi/idea/a11y_firesafety.html:kn'}}}
Run Code Online (Sandbox Code Playgroud)
我的问题在于"u",它表示我的temp(字典词典)中每个项目前面的Unicode编码.如何摆脱那个"你"?
DNS*_*DNS 18
你为什么关心'你'字符?它们只是一个视觉指标; 除非您实际使用str(temp)代码中的结果,否则它们对您的代码没有影响.例如:
>>> test = u"abcd"
>>> test == "abcd"
True
Run Code Online (Sandbox Code Playgroud)
如果它们由于某种原因确实重要,并且您不关心在国际环境中无法使用此代码的后果,那么您可以传入一个自定义object_hook(请参阅此处的json文档)以生成包含字符串内容的字典比unicode.