版權聲明:本文為博主原創文章,未經允許不得轉載。 ...
#!/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)
版權聲明:本文為博主原創文章,未經允許不得轉載。