我有一个json对象数组,如下所示:
{
"testcases": {
"testcase": {
"custom-fields": {
"custom-field": [{
"@id": "testCaseID",
"@content": "shotwell15"
}, {
"#text": "-",
"@id": "casecomponent"
}, {
"#text": "critical",
"@id": "caseimportance"
}]
},
"title": "Shotwell 15"
}
}
}
我尝试使用python并根据@id
的“值”从custom-field
数组中获取对象,如下所示:
查找对象:
{
"#text": "critical",
"@id": "caseimportance"
}
基于“案例重要性”的价值观
我试着用过滤器,但似乎不起作用。我觉得不应该这么难。在javascript或ruby中非常简单的事情。在ruby中,我可以使用.select方法
在Python中,可以使用list comprehension类似于Ruby的select:
Python还有一个与Ruby的select更直接的过滤器:
Python 2:
Python 3:
然而,列表理解通常被认为是更具Python性的。你知道吗
python模块re有一个搜索函数,您可以查看它,它允许您过滤掉特定的单词,然后使用索引来选择json文件中围绕该单词的其他单词/文本。你知道吗
相关问题 更多 >
编程相关推荐