您的位置:首页 > 编程语言 > Python开发

python 提取key 为中文的json 串方法

2019-01-23 12:21 666 查看

示例:

# -*- 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")]
###好地方

以上这篇python 提取key 为中文的json 串方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: