本文介绍了使用Python将JSON字符串转换为dict的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对Python中的JSON感到有些困惑.在我看来,这就像一本字典,因此我正在尝试这样做:
I'm a little bit confused with JSON in Python.To me, it seems like a dictionary, and for that reasonI'm trying to do that:
{
"glossary":
{
"title": "example glossary",
"GlossDiv":
{
"title": "S",
"GlossList":
{
"GlossEntry":
{
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef":
{
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
但是当我执行print dict(json)
时,会出现错误.
But when I do print dict(json)
, it gives an error.
如何将该字符串转换为结构,然后调用json["title"]
以获得示例词汇表"?
How can I transform this string into a structure and then call json["title"]
to obtain "example glossary"?
推荐答案
import json
d = json.loads(j)
print d['glossary']['title']
这篇关于使用Python将JSON字符串转换为dict的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!