python dict 中的中文处理

dict1 = {'中':'国 '}
print dict1 ##{'\xc3\xa4\xc2\xb8\xc2\xad': '\xc3\xa5\xc2\x9b\xc2\xbd'}
import json
json1 = json.dumps(dict1) 
print json1   ##{"\u00e4\u00b8\u00ad": "\u00e5\u009b\u00bd"}
print json1.decode('raw_unicode_escape') ##{"中": "国"}

s = '{"中": "国"}'
dict2 = json.loads(s)
json2 = json.dumps(dict2)
print json2.decode('raw_unicode_escape') ##{"中": "国"}

转载于:https://www.cnblogs.com/sandy-t/p/9550563.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值