I am writing a Java function that restructures some JSON I am getting from a server and I am running into an issue trying to create a JSONArray:
JSONObject jsonObject = jsonObj.getJSONObject("facet_counts").getJSONObject("facet_fields");
Iterator<String> keys = jsonObject.keys();
jsonStr = jsonStr + "\"facetCounts\": {";
while(keys.hasNext()) {
String key = keys.next();
jsonStr = jsonStr + "\"" + key + "\":";
if (jsonObject.get(key) instanceof JSONArray) {
JSONArray facets = jsonObject.get(key);
I am checking if jsonObject.get(key) is an instanceof JSONArray, but it keeps throwing the error incompatible types: java.lang.Object cannot be converted to org.json.JSONArray.
getJSONArray