在python中将unicode json转换为普通json [英] Convert unicode json to normal json in python

查看:117
本文介绍了在python中将unicode json转换为普通json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过在我的python代码中执行request.json,我得到了以下json:{u'a': u'aValue', u'b': u'bValue', u'c': u'cValue'}.现在,我想将unicode json转换为普通的json,应该是这样的:{"a": "aValue", "b": "bValue", "c": "cValue"}.我如何完成这项工作,而不必进行任何手动更换?请帮忙.

I got the following json: {u'a': u'aValue', u'b': u'bValue', u'c': u'cValue'} by doing request.json in my python code. Now, I want to convert the unicode json to normal json, something which should like this: {"a": "aValue", "b": "bValue", "c": "cValue"}. How do I get this done, without having to do any manual replacements? Please help.

推荐答案

{u'a':u'aValue',u'b':u'bValue',u'c':u'cValue'}是一个您将其称为unicode json的字典.现在,以您的语言,如果您想从中使用常规的json,则只需执行以下操作即可:

{u'a': u'aValue', u'b': u'bValue', u'c': u'cValue'} is a dictionary which you are calling as unicode json. Now, in your language if you want a regular json from this then just do something like this:

x={u'a': u'aValue', u'b': u'bValue', u'c': u'cValue'}
y=json.dumps(x)
print y

输出将为{"a":"aValue","c":"cValue","b":"bValue"}

The output will be {"a": "aValue", "c": "cValue", "b": "bValue"}

这篇关于在python中将unicode json转换为普通json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆