本文介绍了带有unicode的简单json转储函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是使用python2.4版本的简单json的示例运行
Here is a sample run of simple json using python2.4 version
>>> >>> orig='{"key1":"Val", "key2":"val2"}' >>> origDict = simplejson.loads(orig) >>> origDict {'key2': 'val2', 'key1': 'Val'} >>> origDict['key2'] = '\xe4\xbd\xa0\xe5\xa5\xbd' >>> simplejson.dumps(origDict) '{"key2": "\\u4f60\\u597d", "key1": "Val"}'转储函数将字节字符串替换为unicode版本.有没有办法让它不做而只返回'{"key2":"\ xe4 \ xbd \ xa0 \ xe5 \ xa5 \ xbd","key1":"Val"}'?
The dumps functions is replacing the byte string with the unicode version. Is there a way to make it not do that and just return '{"key2": "\xe4\xbd\xa0\xe5\xa5\xbd", "key1": "Val"}' ?
推荐答案通过ensure_ascii=False,然后手动编码.
更多推荐
带有unicode的简单json转储函数
发布评论