我对Python中的JSON感到有些困惑。在我看来,这就像是一本字典,出于这个原因,我正在尝试这样做:
{ "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),它会给出一个错误。
print dict(json)
如何将该字符串转换为结构,然后调用json["title"]以获得“示例词汇表”?
json["title"]
json.loads()
import json d = json.loads(j) print d['glossary']['title']