网络编程
位置:首页>> 网络编程>> Python编程>> python 提取key 为中文的json 串方法

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

作者:luckygl17  发布时间:2022-02-08 04:55:06 

标签: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")]
###好地方

来源:https://blog.csdn.net/luckgl/article/details/53897085

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com