如何将这个特定的json字符串转换为python字典? [英] How to convert this particular json string into a python dictionary?

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

问题描述

如何转换此字符串->

How do I convert this string ->

 string = [{"name":"sam"}]

像这样进入python字典->

into a python dictionary like so ->

data = {
         "name" : "sam"
       }

推荐答案

In [1]: import json

In [2]: json.loads('[{"name":"sam"}]')
Out[2]: [{u'name': u'sam'}]

这将返回一个列表,列表的第一个元素是所需的字典.

This returns a list, the first element of which is the desired dictionary.

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

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