时间:2020-12-01 11:31:14 | 栏目:Python代码 | 点击:次
示例:
# -*- coding:utf-8 -*- import json strtest = {"中故宫":"好地方","天涯":"北京"} print strtest #####{'\xe4\xb8\xad\xe6\x95\x85\xe5\xae\xab': '\xe5\xa5\xbd\xe5\x9c\xb0\xe6\x96\xb9', '\xe5\xa4\xa9\xe6\xb6\xaf': '\xe5\x8c\x97\xe4\xba\xac'} strtestObj = json.loads(json.dumps(strtest)) print ">>strtestObj ",strtestObj ###{u'\u5929\u6daf': u'\u5317\u4eac', u'\u4e2d\u6545\u5bab': u'\u597d\u5730\u65b9'} print "test type " , type(strtestObj) ###<type 'dict'> print "trans>>> ","中故宫".decode("utf-8") ###中故宫 print ">>>>>strtestObj ",strtestObj["中故宫".decode("utf-8")] ###好地方