2014-12-31 106 views
0

一個值,下面我有jsonSlurper:獲取基於其他值

[ 
    { 
     "level3": "level3Value1", 
     "level4": "level4value1" 
    }, 
    { 
     "level3": "level3Value2", 
     "level4": "level4value2" 
    }, 
    { 
     "level3": "level3Value3", 
     "level4": "level4value3" 
    }, 
    { 
     "level3": "level3Value4", 
     "level4": "level4value4" 
    }, 
    { 
     "level3": "level3Value5", 
     "level4": "level4value5" 
    } 
] 

JSON響應給我需要根據使用JsonSlurper level3value選擇level4value

回答

1

使用find以獲取列表元素containining您所需的鍵/值對

println([["level3": "level3Value3", "level4": "level4value3"], 
     ["level3": "level3Value4", "level4": "level4value4"], 
     ].find{ it.level4=='level4value4' }.level3)