Example usage for com.google.gson JsonParser parse

List of usage examples for com.google.gson JsonParser parse

Introduction

In this page you can find the example usage for com.google.gson JsonParser parse.

Prototype

@Deprecated
public JsonElement parse(JsonReader json) throws JsonIOException, JsonSyntaxException 

Source Link

Usage

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

License:Open Source License

public static TargetingGeoLocationPoliticalDistrict loadJSON(String json, APIContext context) {
    TargetingGeoLocationPoliticalDistrict targetingGeoLocationPoliticalDistrict = getGson().fromJson(json,
            TargetingGeoLocationPoliticalDistrict.class);
    if (context.isDebug()) {
        JsonParser parser = new JsonParser();
        JsonElement o1 = parser.parse(json);
        JsonElement o2 = parser.parse(targetingGeoLocationPoliticalDistrict.toString());
        if (o1.getAsJsonObject().get("__fb_trace_id__") != null) {
            o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__"));
        }//from ww  w .  j a v a  2  s .c om
        if (!o1.equals(o2)) {
            context.log("[Warning] When parsing response, object is not consistent with JSON:");
            context.log("[JSON]" + o1);
            context.log("[Object]" + o2);
        }
        ;
    }
    targetingGeoLocationPoliticalDistrict.context = context;
    targetingGeoLocationPoliticalDistrict.rawValue = json;
    return targetingGeoLocationPoliticalDistrict;
}

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

License:Open Source License

public static APINodeList<TargetingGeoLocationPoliticalDistrict> parseResponse(String json, APIContext context,
        APIRequest request) throws MalformedResponseException {
    APINodeList<TargetingGeoLocationPoliticalDistrict> targetingGeoLocationPoliticalDistricts = new APINodeList<TargetingGeoLocationPoliticalDistrict>(
            request, json);//from  ww w.j  a va2  s. com
    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++) {
                targetingGeoLocationPoliticalDistricts
                        .add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return targetingGeoLocationPoliticalDistricts;
        } 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;
                    targetingGeoLocationPoliticalDistricts.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++) {
                        targetingGeoLocationPoliticalDistricts
                                .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()) {
                                targetingGeoLocationPoliticalDistricts
                                        .add(loadJSON(entry.getValue().toString(), context));
                            }
                            break;
                        }
                    }
                    if (!isRedownload) {
                        targetingGeoLocationPoliticalDistricts.add(loadJSON(obj.toString(), context));
                    }
                }
                return targetingGeoLocationPoliticalDistricts;
            } 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()) {
                    targetingGeoLocationPoliticalDistricts.add(loadJSON(entry.getValue().toString(), context));
                }
                return targetingGeoLocationPoliticalDistricts;
            } 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)) {
                        targetingGeoLocationPoliticalDistricts.add(loadJSON(value.toString(), context));
                    } else {
                        isIdIndexedArray = false;
                        break;
                    }
                }
                if (isIdIndexedArray) {
                    return targetingGeoLocationPoliticalDistricts;
                }

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

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

License:Open Source License

public static TargetingGeoLocationRegion loadJSON(String json, APIContext context) {
    TargetingGeoLocationRegion targetingGeoLocationRegion = getGson().fromJson(json,
            TargetingGeoLocationRegion.class);
    if (context.isDebug()) {
        JsonParser parser = new JsonParser();
        JsonElement o1 = parser.parse(json);
        JsonElement o2 = parser.parse(targetingGeoLocationRegion.toString());
        if (o1.getAsJsonObject().get("__fb_trace_id__") != null) {
            o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__"));
        }//  w  w w  . j  a  v a  2s  . co  m
        if (!o1.equals(o2)) {
            context.log("[Warning] When parsing response, object is not consistent with JSON:");
            context.log("[JSON]" + o1);
            context.log("[Object]" + o2);
        }
        ;
    }
    targetingGeoLocationRegion.context = context;
    targetingGeoLocationRegion.rawValue = json;
    return targetingGeoLocationRegion;
}

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

License:Open Source License

public static APINodeList<TargetingGeoLocationRegion> parseResponse(String json, APIContext context,
        APIRequest request) throws MalformedResponseException {
    APINodeList<TargetingGeoLocationRegion> targetingGeoLocationRegions = new APINodeList<TargetingGeoLocationRegion>(
            request, json);//from www.j a v  a 2s  .  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++) {
                targetingGeoLocationRegions.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return targetingGeoLocationRegions;
        } 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;
                    targetingGeoLocationRegions.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++) {
                        targetingGeoLocationRegions
                                .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()) {
                                targetingGeoLocationRegions.add(loadJSON(entry.getValue().toString(), context));
                            }
                            break;
                        }
                    }
                    if (!isRedownload) {
                        targetingGeoLocationRegions.add(loadJSON(obj.toString(), context));
                    }
                }
                return targetingGeoLocationRegions;
            } 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()) {
                    targetingGeoLocationRegions.add(loadJSON(entry.getValue().toString(), context));
                }
                return targetingGeoLocationRegions;
            } 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)) {
                        targetingGeoLocationRegions.add(loadJSON(value.toString(), context));
                    } else {
                        isIdIndexedArray = false;
                        break;
                    }
                }
                if (isIdIndexedArray) {
                    return targetingGeoLocationRegions;
                }

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

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

License:Open Source License

public static TargetingGeoLocationZip loadJSON(String json, APIContext context) {
    TargetingGeoLocationZip targetingGeoLocationZip = getGson().fromJson(json, TargetingGeoLocationZip.class);
    if (context.isDebug()) {
        JsonParser parser = new JsonParser();
        JsonElement o1 = parser.parse(json);
        JsonElement o2 = parser.parse(targetingGeoLocationZip.toString());
        if (o1.getAsJsonObject().get("__fb_trace_id__") != null) {
            o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__"));
        }// ww w  .  j ava  2 s  .c  o  m
        if (!o1.equals(o2)) {
            context.log("[Warning] When parsing response, object is not consistent with JSON:");
            context.log("[JSON]" + o1);
            context.log("[Object]" + o2);
        }
        ;
    }
    targetingGeoLocationZip.context = context;
    targetingGeoLocationZip.rawValue = json;
    return targetingGeoLocationZip;
}

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

License:Open Source License

public static APINodeList<TargetingGeoLocationZip> parseResponse(String json, APIContext context,
        APIRequest request) throws MalformedResponseException {
    APINodeList<TargetingGeoLocationZip> targetingGeoLocationZips = new APINodeList<TargetingGeoLocationZip>(
            request, json);// www .j  a v  a  2s.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++) {
                targetingGeoLocationZips.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return targetingGeoLocationZips;
        } 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;
                    targetingGeoLocationZips.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++) {
                        targetingGeoLocationZips
                                .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()) {
                                targetingGeoLocationZips.add(loadJSON(entry.getValue().toString(), context));
                            }
                            break;
                        }
                    }
                    if (!isRedownload) {
                        targetingGeoLocationZips.add(loadJSON(obj.toString(), context));
                    }
                }
                return targetingGeoLocationZips;
            } 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()) {
                    targetingGeoLocationZips.add(loadJSON(entry.getValue().toString(), context));
                }
                return targetingGeoLocationZips;
            } 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)) {
                        targetingGeoLocationZips.add(loadJSON(value.toString(), context));
                    } else {
                        isIdIndexedArray = false;
                        break;
                    }
                }
                if (isIdIndexedArray) {
                    return targetingGeoLocationZips;
                }

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

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

License:Open Source License

public static TargetingProductAudienceSpec loadJSON(String json, APIContext context) {
    TargetingProductAudienceSpec targetingProductAudienceSpec = getGson().fromJson(json,
            TargetingProductAudienceSpec.class);
    if (context.isDebug()) {
        JsonParser parser = new JsonParser();
        JsonElement o1 = parser.parse(json);
        JsonElement o2 = parser.parse(targetingProductAudienceSpec.toString());
        if (o1.getAsJsonObject().get("__fb_trace_id__") != null) {
            o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__"));
        }/*w  ww  .  ja  va 2  s .  co m*/
        if (!o1.equals(o2)) {
            context.log("[Warning] When parsing response, object is not consistent with JSON:");
            context.log("[JSON]" + o1);
            context.log("[Object]" + o2);
        }
        ;
    }
    targetingProductAudienceSpec.context = context;
    targetingProductAudienceSpec.rawValue = json;
    return targetingProductAudienceSpec;
}

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

License:Open Source License

public static APINodeList<TargetingProductAudienceSpec> parseResponse(String json, APIContext context,
        APIRequest request) throws MalformedResponseException {
    APINodeList<TargetingProductAudienceSpec> targetingProductAudienceSpecs = new APINodeList<TargetingProductAudienceSpec>(
            request, json);//from   w  w w  .j a v a 2 s.  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++) {
                targetingProductAudienceSpecs.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return targetingProductAudienceSpecs;
        } 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;
                    targetingProductAudienceSpecs.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++) {
                        targetingProductAudienceSpecs
                                .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()) {
                                targetingProductAudienceSpecs
                                        .add(loadJSON(entry.getValue().toString(), context));
                            }
                            break;
                        }
                    }
                    if (!isRedownload) {
                        targetingProductAudienceSpecs.add(loadJSON(obj.toString(), context));
                    }
                }
                return targetingProductAudienceSpecs;
            } 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()) {
                    targetingProductAudienceSpecs.add(loadJSON(entry.getValue().toString(), context));
                }
                return targetingProductAudienceSpecs;
            } 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)) {
                        targetingProductAudienceSpecs.add(loadJSON(value.toString(), context));
                    } else {
                        isIdIndexedArray = false;
                        break;
                    }
                }
                if (isIdIndexedArray) {
                    return targetingProductAudienceSpecs;
                }

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

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

License:Open Source License

public static TargetingProductAudienceSubSpec loadJSON(String json, APIContext context) {
    TargetingProductAudienceSubSpec targetingProductAudienceSubSpec = getGson().fromJson(json,
            TargetingProductAudienceSubSpec.class);
    if (context.isDebug()) {
        JsonParser parser = new JsonParser();
        JsonElement o1 = parser.parse(json);
        JsonElement o2 = parser.parse(targetingProductAudienceSubSpec.toString());
        if (o1.getAsJsonObject().get("__fb_trace_id__") != null) {
            o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__"));
        }//from  w ww  . j  a  va  2s  .  c o m
        if (!o1.equals(o2)) {
            context.log("[Warning] When parsing response, object is not consistent with JSON:");
            context.log("[JSON]" + o1);
            context.log("[Object]" + o2);
        }
        ;
    }
    targetingProductAudienceSubSpec.context = context;
    targetingProductAudienceSubSpec.rawValue = json;
    return targetingProductAudienceSubSpec;
}

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

License:Open Source License

public static APINodeList<TargetingProductAudienceSubSpec> parseResponse(String json, APIContext context,
        APIRequest request) throws MalformedResponseException {
    APINodeList<TargetingProductAudienceSubSpec> targetingProductAudienceSubSpecs = new APINodeList<TargetingProductAudienceSubSpec>(
            request, json);/*from  w  ww. ja v  a  2 s .c o 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++) {
                targetingProductAudienceSubSpecs
                        .add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return targetingProductAudienceSubSpecs;
        } 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;
                    targetingProductAudienceSubSpecs.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++) {
                        targetingProductAudienceSubSpecs
                                .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()) {
                                targetingProductAudienceSubSpecs
                                        .add(loadJSON(entry.getValue().toString(), context));
                            }
                            break;
                        }
                    }
                    if (!isRedownload) {
                        targetingProductAudienceSubSpecs.add(loadJSON(obj.toString(), context));
                    }
                }
                return targetingProductAudienceSubSpecs;
            } 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()) {
                    targetingProductAudienceSubSpecs.add(loadJSON(entry.getValue().toString(), context));
                }
                return targetingProductAudienceSubSpecs;
            } 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)) {
                        targetingProductAudienceSubSpecs.add(loadJSON(value.toString(), context));
                    } else {
                        isIdIndexedArray = false;
                        break;
                    }
                }
                if (isIdIndexedArray) {
                    return targetingProductAudienceSubSpecs;
                }

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