I am trying to fetch testId of the item having name Item2 from following JSON file:
{
"errors": [],
"data": {
"collections": [
{
"testId": 250,
"name": "Item1",
"itemCount": 3
},
{
"testId": 350,
"name": "Item2",
"itemCount": 4
},
{
"testId": 411,
"name": "Item3",
"itemCount": 1
},
{
"testId": 450,
"name": "null",
"itemCount": 0
}
]
}
}
This JSON is response of GET request I ran on postman.
I can fetch value of any key in this JSON but I am not able to add relative conditions like fetching testID of an item with name Item6.
I'm using Array list to fetch values of testID for all elements, which is working fine for me. Can I make any change in the following to achieve what I want?
protected String getTokenValueUnderHierarchy( String responseString) throws ClientProtocolException, IOException {
String responseRecordsTitle = null;
List<String> list = Arrays.asList(responseString.split("testId"));
System.out.println("list.size()::"+list.size());
for (int i=0;i<list.size();i++){
System.out.println("List Element:"+list.get(i));
responseRecordsTitle = getTokenValue(responseString,"testId");
}
return responseRecordsTitle;
}
PS: getTokenValue(String,String) is a function which I've created to fetch value and it works fine.