我试图从JSON数据中的两个特定项中提取键/值对
数据如下所示:
[{"voc": "UAT",
"concepts":[{"prefLabel":"Solar system",
"uri":"http://astrothesaurus.org/uat/1528", "score":"15" },
{"prefLabel":"X-ray astronomy",
"uri":"http://astrothesaurus.org/uat/1810", "score":"9" },
{"prefLabel":"Gamma-ray astronomy",
"uri":"http://astrothesaurus.org/uat/628", "score":"9" }
]}]
我只是尝试使用for循环来检索prefLabel和score,该循环将它们保存到元组中,以便稍后附加到我当前的空数据列表中
这是我当前的循环,但它返回“错误类型”错误:
for concepts in voc_list:
for prefLabel, score in concepts.items():
data_tuple = (prefLabel, score)
data.append(data_tuple)`
感谢您的帮助
您可以搜索词典列表,并在
key
与所需字符串匹配时附加到data
列表:相关问题 更多 >
编程相关推荐