带有unicode的简单json转储函数

编程入门 行业动态 更新时间:2024-10-26 08:22:12
本文介绍了带有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转储函数

本文发布于:2023-10-28 19:55:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537620.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   简单   unicode   json

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!