There is a very nice KeyFinder example on the json-simple docs
But if I try to get an array, it will only return me the first element json
{"foo":
{"bar":
{"foobar":{
"items":["item1","item2","item3"]
}
}
}
}
If I use the example of keyFinder and search for "items", I only get "item1" whereas I want to be able to use the whole array.
Example of what the keyFinder does / how it is working:
KeyFinder finder = new KeyFinder();
finder.setMatchKey("items");
try{
while(!finder.isEnd()){
if(finder.isFound)
System.out.println("finder.getValue() -->" + finder.getValue()
}
}//...
How I do currently:
Object obj = parser.parse(jsonText);
JSONObject jsonObject = (JSONObject) obj;
JSONObject jsonTags = (JSONObject) ((JSONObject) ((JSONObject) jsonObject.get("foo")).get("bar")).get("foobar");
String tags = (String) jsonTags.get("items").toString().replaceAll("[^A-Za-z0-9,]","");
String[] vaca = tags.split(",");
for(String s : vaca) {
list.add(s);
System.out.println(s);
}
My question is how to get the array without knowing the "path" foo >> bar >> foobar to get the "items" array by its key.