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

后端 未结 2 1895
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-13 14:57

How do I convert this string ->

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

into a python dictionary like so ->

data = {
         \"name         


        
相关标签:
2条回答
  • 2021-01-13 15:29
    string = [{ "name" : "sam" }]
    data = string[0]
    

    now the data is the dict

    0 讨论(0)
  • 2021-01-13 15:47
    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.

    0 讨论(0)
提交回复
热议问题