在使用python的json模块对json字串反序列化成python对象的时候出现的字符串都是unicode类型,而不是python内置的str类型.在某种使用场景下用户必须做显式的转换才能正常使用,徒增一些麻烦,为解决这一问题封装下述函数. def convert(input): if isinstance(input, dict): return {convert(key): convert(value) for key, value in input.iteritems()} elif i…
Python load json file with UTF-8 BOM header - Stack Overflow 3 down vote Since json.load(stream) uses json.loads(stream.read()) under the hood, it won't be that bad to write a small hepler function that lstrips the BOM: from codecs import BOM_UTF8 de…