1、#coding:utf-8
2、import sys
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
3、解码为unicode
60 def strdecode(sentence):
61 if not isinstance(sentence, unicode):
62 try:
63 sentence = sentence.decode('utf-8')
64 except UnicodeDecodeError:
65 sentence = sentence.decode('gbk', 'ignore')
66 return sentenc
4、汉字字符串按下标操作时,需decode为unicode
5、json 处理Decima datetime.datetime
20 class DecimalJSONEncoder(json.JSONEncoder):
21 def default(self, o):
22 if isinstance(o, decimal.Decimal):
23 return str(o)
24 return super(DecimalJSONEncoder, self).default(o)
json.dumps(result,cls=DecimalJSONEncoder)