Python获取json中key值为中文的value

# -*- coding:UTF-8 -*-

import json

def getPinyinFromLocal(in_hanzi):
	with open("result.txt",'r') as file_name:
		js_localpinyin = json.load(file_name,"utf-8")
		pinyin = js_localpinyin.get(in_hanzi.decode("utf-8"),None)
		if not pinyin:
			return ""
		else:
			return pinyin

需要将文件和key值都转换为unicode编码。

你可能感兴趣的:(Python)