Example usage for com.google.gson JsonElement isJsonArray

List of usage examples for com.google.gson JsonElement isJsonArray

Introduction

In this page you can find the example usage for com.google.gson JsonElement isJsonArray.

Prototype

public boolean isJsonArray() 

Source Link

Document

provides check for verifying if this element is an array or not.

Usage

From source file:com.esotericsoftware.spine.SkeletonJson.java

License:Open Source License

void readCurve(CurveTimeline timeline, int frameIndex, JsonObject valueMap) {
    JsonElement curve = valueMap.has("curve") ? valueMap.get("curve") : null;
    if (curve == null)
        return;//from   w w  w. j  a v  a  2s  .  c om
    if (curve.isJsonPrimitive() && curve.getAsString().equals("stepped"))
        timeline.setStepped(frameIndex);
    else if (curve.isJsonArray()) {
        JsonArray curveArray = curve.getAsJsonArray();
        timeline.setCurve(frameIndex, curveArray.get(0).getAsFloat(), curveArray.get(1).getAsFloat(),
                curveArray.get(2).getAsFloat(), curveArray.get(3).getAsFloat());
    }
}

From source file:com.example.android.xyztouristattractions.ui.AttractionListFragment.java

License:Open Source License

@Override
public void success(JsonElement string, Response response) {
    JsonObject mJsonObject = null;/*from   w  w  w .  java  2s . c  om*/
    List<Attraction> attractionsList = new ArrayList<Attraction>();
    if (string.isJsonObject()) {
        //            Toast.makeText(getActivity(), "OnSuccess--Object" + string.toString(), Toast.LENGTH_LONG).show();
        mJsonObject = string.getAsJsonObject();
        JsonElement mElement = mJsonObject.get("attractions");
        if (mElement.isJsonArray()) {
            JsonArray mArray = mElement.getAsJsonArray();
            HashMap<String, List<Attraction>> ATTRACTIONS = new HashMap<String, List<Attraction>>();

            String city = "";
            for (JsonElement element : mArray) {
                JsonObject attractions = null;
                if (element.isJsonObject()) {
                    attractions = element.getAsJsonObject();
                    JsonObject imageURl = attractions.get("imageUrl").getAsJsonObject();
                    JsonObject secImageURl = attractions.get("secondaryImageUrl").getAsJsonObject();
                    JsonObject location = attractions.get("location").getAsJsonObject();
                    city = attractions.get("city").toString();
                    //                        Toast.makeText(getActivity(), "OnSuccess--" + attractions.get("name") + imageURl.get("uriString")
                    //                                + attractions.get("city") + attractions.get("longDescription")
                    //                                + attractions.get("description"), Toast.LENGTH_LONG).show();
                    //                        String name, String description, String longDescription, Uri imageUrl,
                    //                                Uri secondaryImageUrl, LatLng location, String city
                    attractionsList.add(new Attraction(attractions.get("name").toString(),
                            attractions.get("description").toString(),
                            attractions.get("longDescription").toString(),
                            Uri.parse(imageURl.get("uriString").toString()),
                            Uri.parse(secImageURl.get("uriString").toString()),
                            new LatLng(Float.parseFloat(location.get("latitude").toString()),
                                    Float.parseFloat(location.get("longitude").toString())),
                            attractions.get("city").toString()));
                    Log.d(AttractionListFragment.class.getSimpleName(), imageURl.get("uriString").toString());
                    Log.d(AttractionListFragment.class.getSimpleName(),
                            secImageURl.get("uriString").toString());

                } else
                    Toast.makeText(getActivity(), "OnSuccess--Object--Array--Not Object", Toast.LENGTH_LONG)
                            .show();
            }
            ATTRACTIONS.put(city, attractionsList);

        } else
            Toast.makeText(getActivity(), "OnSuccess--Object--Not Array", Toast.LENGTH_LONG).show();
    } else
        Toast.makeText(getActivity(), "OnSuccess--Not Object", Toast.LENGTH_LONG).show();

    //        DataModel model = new Gson().fromJson(string.toString(), DataModel.class);
    //        List<Attraction> attractions = model.getAttractions();
    mAdapter = new AttractionAdapter(getActivity(), attractionsList);
    recyclerView.setAdapter(mAdapter);
}

From source file:com.exsoloscript.challonge.gson.MatchListAdapter.java

License:Apache License

@Override
public List<Match> deserialize(JsonElement jsonElement, Type type,
        JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
    if (jsonElement.isJsonArray()) {
        JsonArray array = jsonElement.getAsJsonArray();
        List<Match> matches = Lists.newArrayList();

        for (JsonElement arrayElement : array) {
            matches.add(this.gson.fromJson(arrayElement, Match.class));
        }/*from   w ww  .  j  a va  2 s.com*/

        return matches;
    }

    return null;
}

From source file:com.exsoloscript.challonge.gson.ParticipantListAdapter.java

License:Apache License

@Override
public List<Participant> deserialize(JsonElement jsonElement, Type type,
        JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
    if (jsonElement.isJsonArray()) {
        JsonArray array = jsonElement.getAsJsonArray();
        List<Participant> participants = Lists.newArrayList();

        for (JsonElement arrayElement : array) {
            participants.add(this.gson.fromJson(arrayElement, Participant.class));
        }/*ww  w. j  av a2s  . com*/

        return participants;
    }

    return null;
}

From source file:com.facebook.ads.sdk.AdAccount.java

License:Open Source License

public static APINodeList<AdAccount> parseResponse(String json, APIContext context, APIRequest request)
        throws MalformedResponseException {
    APINodeList<AdAccount> adAccounts = new APINodeList<AdAccount>(request, json);
    JsonArray arr;//from  www .  j  a  v a  2  s.  c  o m
    JsonObject obj;
    JsonParser parser = new JsonParser();
    Exception exception = null;
    try {
        JsonElement result = parser.parse(json);
        if (result.isJsonArray()) {
            // First, check if it's a pure JSON Array
            arr = result.getAsJsonArray();
            for (int i = 0; i < arr.size(); i++) {
                adAccounts.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return adAccounts;
        } else if (result.isJsonObject()) {
            obj = result.getAsJsonObject();
            if (obj.has("data")) {
                if (obj.has("paging")) {
                    JsonObject paging = obj.get("paging").getAsJsonObject().get("cursors").getAsJsonObject();
                    String before = paging.has("before") ? paging.get("before").getAsString() : null;
                    String after = paging.has("after") ? paging.get("after").getAsString() : null;
                    adAccounts.setPaging(before, after);
                }
                if (obj.get("data").isJsonArray()) {
                    // Second, check if it's a JSON array with "data"
                    arr = obj.get("data").getAsJsonArray();
                    for (int i = 0; i < arr.size(); i++) {
                        adAccounts.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
                    }
                    ;
                } else if (obj.get("data").isJsonObject()) {
                    // Third, check if it's a JSON object with "data"
                    obj = obj.get("data").getAsJsonObject();
                    boolean isRedownload = false;
                    for (String s : new String[] { "campaigns", "adsets", "ads" }) {
                        if (obj.has(s)) {
                            isRedownload = true;
                            obj = obj.getAsJsonObject(s);
                            for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                                adAccounts.add(loadJSON(entry.getValue().toString(), context));
                            }
                            break;
                        }
                    }
                    if (!isRedownload) {
                        adAccounts.add(loadJSON(obj.toString(), context));
                    }
                }
                return adAccounts;
            } else if (obj.has("images")) {
                // Fourth, check if it's a map of image objects
                obj = obj.get("images").getAsJsonObject();
                for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                    adAccounts.add(loadJSON(entry.getValue().toString(), context));
                }
                return adAccounts;
            } else {
                // Fifth, check if it's an array of objects indexed by id
                boolean isIdIndexedArray = true;
                for (Map.Entry entry : obj.entrySet()) {
                    String key = (String) entry.getKey();
                    if (key.equals("__fb_trace_id__")) {
                        continue;
                    }
                    JsonElement value = (JsonElement) entry.getValue();
                    if (value != null && value.isJsonObject() && value.getAsJsonObject().has("id")
                            && value.getAsJsonObject().get("id") != null
                            && value.getAsJsonObject().get("id").getAsString().equals(key)) {
                        adAccounts.add(loadJSON(value.toString(), context));
                    } else {
                        isIdIndexedArray = false;
                        break;
                    }
                }
                if (isIdIndexedArray) {
                    return adAccounts;
                }

                // Sixth, check if it's pure JsonObject
                adAccounts.clear();
                adAccounts.add(loadJSON(json, context));
                return adAccounts;
            }
        }
    } catch (Exception e) {
        exception = e;
    }
    throw new MalformedResponseException("Invalid response string: " + json, exception);
}

From source file:com.facebook.ads.sdk.AdAccountDeliveryEstimate.java

License:Open Source License

public static APINodeList<AdAccountDeliveryEstimate> parseResponse(String json, APIContext context,
        APIRequest request) throws MalformedResponseException {
    APINodeList<AdAccountDeliveryEstimate> adAccountDeliveryEstimates = new APINodeList<AdAccountDeliveryEstimate>(
            request, json);//from   www . ja v a  2 s.  co m
    JsonArray arr;
    JsonObject obj;
    JsonParser parser = new JsonParser();
    Exception exception = null;
    try {
        JsonElement result = parser.parse(json);
        if (result.isJsonArray()) {
            // First, check if it's a pure JSON Array
            arr = result.getAsJsonArray();
            for (int i = 0; i < arr.size(); i++) {
                adAccountDeliveryEstimates.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return adAccountDeliveryEstimates;
        } else if (result.isJsonObject()) {
            obj = result.getAsJsonObject();
            if (obj.has("data")) {
                if (obj.has("paging")) {
                    JsonObject paging = obj.get("paging").getAsJsonObject().get("cursors").getAsJsonObject();
                    String before = paging.has("before") ? paging.get("before").getAsString() : null;
                    String after = paging.has("after") ? paging.get("after").getAsString() : null;
                    adAccountDeliveryEstimates.setPaging(before, after);
                }
                if (obj.get("data").isJsonArray()) {
                    // Second, check if it's a JSON array with "data"
                    arr = obj.get("data").getAsJsonArray();
                    for (int i = 0; i < arr.size(); i++) {
                        adAccountDeliveryEstimates
                                .add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
                    }
                    ;
                } else if (obj.get("data").isJsonObject()) {
                    // Third, check if it's a JSON object with "data"
                    obj = obj.get("data").getAsJsonObject();
                    boolean isRedownload = false;
                    for (String s : new String[] { "campaigns", "adsets", "ads" }) {
                        if (obj.has(s)) {
                            isRedownload = true;
                            obj = obj.getAsJsonObject(s);
                            for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                                adAccountDeliveryEstimates.add(loadJSON(entry.getValue().toString(), context));
                            }
                            break;
                        }
                    }
                    if (!isRedownload) {
                        adAccountDeliveryEstimates.add(loadJSON(obj.toString(), context));
                    }
                }
                return adAccountDeliveryEstimates;
            } else if (obj.has("images")) {
                // Fourth, check if it's a map of image objects
                obj = obj.get("images").getAsJsonObject();
                for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                    adAccountDeliveryEstimates.add(loadJSON(entry.getValue().toString(), context));
                }
                return adAccountDeliveryEstimates;
            } else {
                // Fifth, check if it's an array of objects indexed by id
                boolean isIdIndexedArray = true;
                for (Map.Entry entry : obj.entrySet()) {
                    String key = (String) entry.getKey();
                    if (key.equals("__fb_trace_id__")) {
                        continue;
                    }
                    JsonElement value = (JsonElement) entry.getValue();
                    if (value != null && value.isJsonObject() && value.getAsJsonObject().has("id")
                            && value.getAsJsonObject().get("id") != null
                            && value.getAsJsonObject().get("id").getAsString().equals(key)) {
                        adAccountDeliveryEstimates.add(loadJSON(value.toString(), context));
                    } else {
                        isIdIndexedArray = false;
                        break;
                    }
                }
                if (isIdIndexedArray) {
                    return adAccountDeliveryEstimates;
                }

                // Sixth, check if it's pure JsonObject
                adAccountDeliveryEstimates.clear();
                adAccountDeliveryEstimates.add(loadJSON(json, context));
                return adAccountDeliveryEstimates;
            }
        }
    } catch (Exception e) {
        exception = e;
    }
    throw new MalformedResponseException("Invalid response string: " + json, exception);
}

From source file:com.facebook.ads.sdk.AdAccountGroup.java

License:Open Source License

public static APINodeList<AdAccountGroup> parseResponse(String json, APIContext context, APIRequest request)
        throws MalformedResponseException {
    APINodeList<AdAccountGroup> adAccountGroups = new APINodeList<AdAccountGroup>(request, json);
    JsonArray arr;/*from w ww  . j  av a  2  s  .  co m*/
    JsonObject obj;
    JsonParser parser = new JsonParser();
    Exception exception = null;
    try {
        JsonElement result = parser.parse(json);
        if (result.isJsonArray()) {
            // First, check if it's a pure JSON Array
            arr = result.getAsJsonArray();
            for (int i = 0; i < arr.size(); i++) {
                adAccountGroups.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return adAccountGroups;
        } else if (result.isJsonObject()) {
            obj = result.getAsJsonObject();
            if (obj.has("data")) {
                if (obj.has("paging")) {
                    JsonObject paging = obj.get("paging").getAsJsonObject().get("cursors").getAsJsonObject();
                    String before = paging.has("before") ? paging.get("before").getAsString() : null;
                    String after = paging.has("after") ? paging.get("after").getAsString() : null;
                    adAccountGroups.setPaging(before, after);
                }
                if (obj.get("data").isJsonArray()) {
                    // Second, check if it's a JSON array with "data"
                    arr = obj.get("data").getAsJsonArray();
                    for (int i = 0; i < arr.size(); i++) {
                        adAccountGroups.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
                    }
                    ;
                } else if (obj.get("data").isJsonObject()) {
                    // Third, check if it's a JSON object with "data"
                    obj = obj.get("data").getAsJsonObject();
                    boolean isRedownload = false;
                    for (String s : new String[] { "campaigns", "adsets", "ads" }) {
                        if (obj.has(s)) {
                            isRedownload = true;
                            obj = obj.getAsJsonObject(s);
                            for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                                adAccountGroups.add(loadJSON(entry.getValue().toString(), context));
                            }
                            break;
                        }
                    }
                    if (!isRedownload) {
                        adAccountGroups.add(loadJSON(obj.toString(), context));
                    }
                }
                return adAccountGroups;
            } else if (obj.has("images")) {
                // Fourth, check if it's a map of image objects
                obj = obj.get("images").getAsJsonObject();
                for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                    adAccountGroups.add(loadJSON(entry.getValue().toString(), context));
                }
                return adAccountGroups;
            } else {
                // Fifth, check if it's an array of objects indexed by id
                boolean isIdIndexedArray = true;
                for (Map.Entry entry : obj.entrySet()) {
                    String key = (String) entry.getKey();
                    if (key.equals("__fb_trace_id__")) {
                        continue;
                    }
                    JsonElement value = (JsonElement) entry.getValue();
                    if (value != null && value.isJsonObject() && value.getAsJsonObject().has("id")
                            && value.getAsJsonObject().get("id") != null
                            && value.getAsJsonObject().get("id").getAsString().equals(key)) {
                        adAccountGroups.add(loadJSON(value.toString(), context));
                    } else {
                        isIdIndexedArray = false;
                        break;
                    }
                }
                if (isIdIndexedArray) {
                    return adAccountGroups;
                }

                // Sixth, check if it's pure JsonObject
                adAccountGroups.clear();
                adAccountGroups.add(loadJSON(json, context));
                return adAccountGroups;
            }
        }
    } catch (Exception e) {
        exception = e;
    }
    throw new MalformedResponseException("Invalid response string: " + json, exception);
}

From source file:com.facebook.ads.sdk.AdAccountGroupResult.java

License:Open Source License

public static APINodeList<AdAccountGroupResult> parseResponse(String json, APIContext context,
        APIRequest request) throws MalformedResponseException {
    APINodeList<AdAccountGroupResult> adAccountGroupResults = new APINodeList<AdAccountGroupResult>(request,
            json);//  w  w w  .jav a 2s  .  c  om
    JsonArray arr;
    JsonObject obj;
    JsonParser parser = new JsonParser();
    Exception exception = null;
    try {
        JsonElement result = parser.parse(json);
        if (result.isJsonArray()) {
            // First, check if it's a pure JSON Array
            arr = result.getAsJsonArray();
            for (int i = 0; i < arr.size(); i++) {
                adAccountGroupResults.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return adAccountGroupResults;
        } else if (result.isJsonObject()) {
            obj = result.getAsJsonObject();
            if (obj.has("data")) {
                if (obj.has("paging")) {
                    JsonObject paging = obj.get("paging").getAsJsonObject().get("cursors").getAsJsonObject();
                    String before = paging.has("before") ? paging.get("before").getAsString() : null;
                    String after = paging.has("after") ? paging.get("after").getAsString() : null;
                    adAccountGroupResults.setPaging(before, after);
                }
                if (obj.get("data").isJsonArray()) {
                    // Second, check if it's a JSON array with "data"
                    arr = obj.get("data").getAsJsonArray();
                    for (int i = 0; i < arr.size(); i++) {
                        adAccountGroupResults.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
                    }
                    ;
                } else if (obj.get("data").isJsonObject()) {
                    // Third, check if it's a JSON object with "data"
                    obj = obj.get("data").getAsJsonObject();
                    boolean isRedownload = false;
                    for (String s : new String[] { "campaigns", "adsets", "ads" }) {
                        if (obj.has(s)) {
                            isRedownload = true;
                            obj = obj.getAsJsonObject(s);
                            for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                                adAccountGroupResults.add(loadJSON(entry.getValue().toString(), context));
                            }
                            break;
                        }
                    }
                    if (!isRedownload) {
                        adAccountGroupResults.add(loadJSON(obj.toString(), context));
                    }
                }
                return adAccountGroupResults;
            } else if (obj.has("images")) {
                // Fourth, check if it's a map of image objects
                obj = obj.get("images").getAsJsonObject();
                for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                    adAccountGroupResults.add(loadJSON(entry.getValue().toString(), context));
                }
                return adAccountGroupResults;
            } else {
                // Fifth, check if it's an array of objects indexed by id
                boolean isIdIndexedArray = true;
                for (Map.Entry entry : obj.entrySet()) {
                    String key = (String) entry.getKey();
                    if (key.equals("__fb_trace_id__")) {
                        continue;
                    }
                    JsonElement value = (JsonElement) entry.getValue();
                    if (value != null && value.isJsonObject() && value.getAsJsonObject().has("id")
                            && value.getAsJsonObject().get("id") != null
                            && value.getAsJsonObject().get("id").getAsString().equals(key)) {
                        adAccountGroupResults.add(loadJSON(value.toString(), context));
                    } else {
                        isIdIndexedArray = false;
                        break;
                    }
                }
                if (isIdIndexedArray) {
                    return adAccountGroupResults;
                }

                // Sixth, check if it's pure JsonObject
                adAccountGroupResults.clear();
                adAccountGroupResults.add(loadJSON(json, context));
                return adAccountGroupResults;
            }
        }
    } catch (Exception e) {
        exception = e;
    }
    throw new MalformedResponseException("Invalid response string: " + json, exception);
}

From source file:com.facebook.ads.sdk.AdAccountRoas.java

License:Open Source License

public static APINodeList<AdAccountRoas> parseResponse(String json, APIContext context, APIRequest request)
        throws MalformedResponseException {
    APINodeList<AdAccountRoas> adAccountRoass = new APINodeList<AdAccountRoas>(request, json);
    JsonArray arr;//from   w  ww  . jav  a 2s . c o  m
    JsonObject obj;
    JsonParser parser = new JsonParser();
    Exception exception = null;
    try {
        JsonElement result = parser.parse(json);
        if (result.isJsonArray()) {
            // First, check if it's a pure JSON Array
            arr = result.getAsJsonArray();
            for (int i = 0; i < arr.size(); i++) {
                adAccountRoass.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return adAccountRoass;
        } else if (result.isJsonObject()) {
            obj = result.getAsJsonObject();
            if (obj.has("data")) {
                if (obj.has("paging")) {
                    JsonObject paging = obj.get("paging").getAsJsonObject().get("cursors").getAsJsonObject();
                    String before = paging.has("before") ? paging.get("before").getAsString() : null;
                    String after = paging.has("after") ? paging.get("after").getAsString() : null;
                    adAccountRoass.setPaging(before, after);
                }
                if (obj.get("data").isJsonArray()) {
                    // Second, check if it's a JSON array with "data"
                    arr = obj.get("data").getAsJsonArray();
                    for (int i = 0; i < arr.size(); i++) {
                        adAccountRoass.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
                    }
                    ;
                } else if (obj.get("data").isJsonObject()) {
                    // Third, check if it's a JSON object with "data"
                    obj = obj.get("data").getAsJsonObject();
                    boolean isRedownload = false;
                    for (String s : new String[] { "campaigns", "adsets", "ads" }) {
                        if (obj.has(s)) {
                            isRedownload = true;
                            obj = obj.getAsJsonObject(s);
                            for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                                adAccountRoass.add(loadJSON(entry.getValue().toString(), context));
                            }
                            break;
                        }
                    }
                    if (!isRedownload) {
                        adAccountRoass.add(loadJSON(obj.toString(), context));
                    }
                }
                return adAccountRoass;
            } else if (obj.has("images")) {
                // Fourth, check if it's a map of image objects
                obj = obj.get("images").getAsJsonObject();
                for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                    adAccountRoass.add(loadJSON(entry.getValue().toString(), context));
                }
                return adAccountRoass;
            } else {
                // Fifth, check if it's an array of objects indexed by id
                boolean isIdIndexedArray = true;
                for (Map.Entry entry : obj.entrySet()) {
                    String key = (String) entry.getKey();
                    if (key.equals("__fb_trace_id__")) {
                        continue;
                    }
                    JsonElement value = (JsonElement) entry.getValue();
                    if (value != null && value.isJsonObject() && value.getAsJsonObject().has("id")
                            && value.getAsJsonObject().get("id") != null
                            && value.getAsJsonObject().get("id").getAsString().equals(key)) {
                        adAccountRoass.add(loadJSON(value.toString(), context));
                    } else {
                        isIdIndexedArray = false;
                        break;
                    }
                }
                if (isIdIndexedArray) {
                    return adAccountRoass;
                }

                // Sixth, check if it's pure JsonObject
                adAccountRoass.clear();
                adAccountRoass.add(loadJSON(json, context));
                return adAccountRoass;
            }
        }
    } catch (Exception e) {
        exception = e;
    }
    throw new MalformedResponseException("Invalid response string: " + json, exception);
}

From source file:com.facebook.ads.sdk.AdAccountRoasCohorts.java

License:Open Source License

public static APINodeList<AdAccountRoasCohorts> parseResponse(String json, APIContext context,
        APIRequest request) {/* ww  w  .  j  ava  2 s .c om*/
    APINodeList<AdAccountRoasCohorts> adAccountRoasCohortss = new APINodeList<AdAccountRoasCohorts>(request,
            json);
    JsonArray arr;
    JsonObject obj;
    JsonParser parser = new JsonParser();
    try {
        JsonElement result = parser.parse(json);
        if (result.isJsonArray()) {
            // First, check if it's a pure JSON Array
            arr = result.getAsJsonArray();
            for (int i = 0; i < arr.size(); i++) {
                adAccountRoasCohortss.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return adAccountRoasCohortss;
        } else if (result.isJsonObject()) {
            obj = result.getAsJsonObject();
            if (obj.has("data")) {
                try {
                    JsonObject paging = obj.get("paging").getAsJsonObject().get("cursors").getAsJsonObject();
                    adAccountRoasCohortss.setPaging(paging.get("before").getAsString(),
                            paging.get("after").getAsString());
                } catch (Exception ignored) {
                }
                if (obj.get("data").isJsonArray()) {
                    // Second, check if it's a JSON array with "data"
                    arr = obj.get("data").getAsJsonArray();
                    for (int i = 0; i < arr.size(); i++) {
                        adAccountRoasCohortss.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
                    }
                    ;
                } else if (obj.get("data").isJsonObject()) {
                    // Third, check if it's a JSON object with "data"
                    obj = obj.get("data").getAsJsonObject();
                    adAccountRoasCohortss.add(loadJSON(obj.toString(), context));
                }
                return adAccountRoasCohortss;
            } else if (obj.has("images")) {
                // Fourth, check if it's a map of image objects
                obj = obj.get("images").getAsJsonObject();
                for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                    adAccountRoasCohortss.add(loadJSON(entry.getValue().toString(), context));
                }
                return adAccountRoasCohortss;
            } else {
                // Fifth, check if it's pure JsonObject
                adAccountRoasCohortss.add(loadJSON(json, context));
                return adAccountRoasCohortss;
            }
        }
    } catch (Exception e) {
    }
    return null;
}