在Python中将字符串转换为字典? [英] Convert a string to a dictionary in Python?

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

问题描述

我正在从twitter提取数据,twitter是python字典的结构,但是数据保存在字符串变量中.

I am pulling data from twitter, which is in the structure of a python dictionary, but the data is held in a string variable.

如何在Python中将此字符串变量转换为字典?

How can I convert this string variable to a dictionary in Python?

感谢您的帮助!

此处是数据的示例.

推荐答案

您可能正在寻找 json 模块.

例如,

In [165]: json.loads('{"a": 0, "c": 0, "b": 0}')
Out[165]: {u'a': 0, u'b': 0, u'c': 0}

这篇关于在Python中将字符串转换为字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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