#!/usr/bin/python import sys import json as js import codecs import collections #reload(sys) #sys.setdefaultencoding('utf-8') #convert utf8 to ascii def convert(data): if isinstance(data, basestring): return data.encode('utf-8') elif isinstance(data, collections.Mapping): return dict(map(convert, data.iteritems())) elif isinstance(data, collections.Iterable): return type(data)(map(convert, data)) else: return data with codecs.open(sys.argv[1], 'r', encoding='utf-8') as json_data: data = js.load(json_data) data = convert(data)
版权声明:本文为博主原创文章,未经允许不得转载。