python json dict,使用Python将JSON字符串转换为dict
发布日期:2022-02-21 12:50:43 浏览次数:37 分类:技术文章

本文共 744 字,大约阅读时间需要 2 分钟。

I'm a little bit confused with JSON in Python.

To me, it seems like a dictionary, and for that reason

I'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"

}

}

}

}

}

But when I do print dict(json), it gives an error.

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']

转载地址:https://blog.csdn.net/weixin_33958381/article/details/118830453 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:2019初三计算机考试模拟,2019年初三第一次模拟考试,还有不到100天,你真的准备好了么?...
下一篇:将计算机与局域网互连 需要_,计算机与局域网连接需要的硬件是什么

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月03日 22时15分22秒