" />
开发者

How to convert this particular json string into a python dictionary?

开发者 https://www.devze.com 2023-03-23 11:08 出处:网络
How do I convert this string -> 开发者_StackOverflow社区 string = [{\"name\":\"sam\"}] into a python dictionary like so ->

How do I convert this string ->

开发者_StackOverflow社区 string = [{"name":"sam"}]

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.


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

now the data is the dict

0

精彩评论

暂无评论...
验证码 换一张
取 消