python 提取key 爲中文的json 串

示例:

# -*- 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")]
###好地方
發佈了47 篇原創文章 · 獲贊 6 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章