使用工具 PyCharm 2018.2.3 Anaconda Navigator Python 3.6 解析目标 [ { "导航鸭 ♪(^∀^●)ノ" : [ { "name" : "Bilibili" , "href" : "https://www.bilibili.com/" , "desc" : "哔哩哔哩 (゜-゜)つロ 干杯~" , "logo" :
使用工具
PyCharm 2018.2.3
Anaconda Navigator
Python 3.6
解析目标
[{
"导航鸭 ♪(^∀^●)ノ": [
{
"name": "Bilibili",
"href": "https://www.bilibili.com/",
"desc": "哔哩哔哩 (゜-゜)つロ 干杯~",
"logo": "http://img.558idc.com/uploadfile/allimg/python/68318509jw8f3sh9uz4ukj20sg0sggnf.jpg"
},
{
"name": "腾讯云",
"href": "https://cloud.tencent.com/",
"desc": "深圳市腾讯计算机系统有限公司",
"logo": "http://img.558idc.com/uploadfile/allimg/python/005EbuQTly8fran1nvvfuj305k05kt8n.jpg"
},
{
"name": "",
"href": "",
"desc": "全国最大的交友社区",
"logo": "http://img.558idc.com/uploadfile/allimg/python/5375acf5gw1dtaou6dgqwj.jpg"
},
{
"name": "网易云课堂",
"href": "https://study.163.com/",
"desc": "我的职业课堂",
"logo": "http://img.558idc.com/uploadfile/allimg/python/ba94de6bjw1eldy8chcy0j205k05kq2r.jpg"
}
]
}
]
代码示例
content_dict = json.loads(resp) # 将解析目标字符串类型转化成字典类型
# print(content_dict, type(content_dict)) # 打印内容
for content in content_dict:
# print(content) # 打印列表中的内容
for key, value in content.items(): # 取出python在字典嵌套的列表
# print(key, value) # 取出 key和 对应的 value
# print(value)
# for values in value: # 遍历列表 中所有的 字典
# print(values)
# for values in value:
# print(values['name']) # 获取所有name 对应的 value值
for values in value:
print(values['logo']) # 获取所有logo 对应的 value值