下面是要分析的模块:
('images\\Principales\\Screenshot_1.png', '{"categories":[{"name":"abstract_","score":0.00390625},{"name":"outdoor_","score":0.01171875},{"name":"outdoor_road","score":0.41796875}],"description":{"tags":["road","building","outdoor","scene","street","city","sitting","empty","light","view","driving","red","sign","intersection","green","large","riding","traffic","white","tall","blue","fire"],"captions":[{"text":"a view of a city street","confidence":0.83864323826716347}]},"requestId":"73fc14d5-653f-4a0a-a45a-e7a425580361","metadata":{"width":150,"height":153,"format":"Png"},"color":{"dominantColorForeground":"Grey","dominantColorBackground":"Grey","dominantColors":["Grey"],"accentColor":"274A68","isBWImg":false}}')
我需要提取“description”后的所有元素,但我不知道怎么做。。。(事实上,我需要这些元素:
^{pr2}$我已经找了好几分钟了,但我不知道怎么做!我对学习“列表”元素有点初学者,但我仍然很难理解。在
“For”循环只返回'images\\Principales\\Screenshot_1.png'
,然后剩下大的块。。。在
你有解决办法吗?在
谢谢你的忠告!在
编辑:
实际上,它实际上是JSON!感谢帮助我的人:) 为了提取包含在第二个块中的所需元素,我只需这样做:
import json
ElementSeparate= '{"categories":[{"name":"abstract_","score":0.00390625},{"name":"outdoor_","score":0.01171875},{"name":"outdoor_road","score":0.41796875}],"description":{"tags":["road","building","outdoor","scene","street","city","sitting","empty","light","view","driving","red","sign","intersection","green","large","riding","traffic","white","tall","blue","fire"],"captions":[{"text":"a view of a city street","confidence":0.83864323826716347}]},"requestId":"73fc14d5-653f-4a0a-a45a-e7a425580361","metadata":{"width":150,"height":153,"format":"Png"},"color":{"dominantColorForeground":"Grey","dominantColorBackground":"Grey","dominantColors":["Grey"],"accentColor":"274A68","isBWImg":false}'
ElementSeparate = json.loads(ElementSeparate)
for a in ElementSeparate['description']['tags']:
print a
在我看来,你好像在尝试解析JSON。应该对数组的第二个元素使用JSON解析器。你要么要回单子,要么要字典。然后您就可以从“description”key has中提取数据。在
https://docs.python.org/3/library/json.html
相关问题 更多 >
编程相关推荐