0

I have run in to an issue, while converting my iOS app to android.

The database is structured such that there are "stations", these stations can have multiple images attached, in the parse database, the images are an array of imagePointers.

When i wanted to get the images out in iOS here is what i did:

stations = object in this case

// Get a single image
if ([[object objectForKey:@"imagePointers"] objectAtIndex:0] != [NSNull null]) {
    PFFile *imageFile = [[[object objectForKey:@"imagePointers"] objectAtIndex:0] objectForKey:@"image"];
    cell.coverImageView.file = imageFile;
    [cell.coverImageView loadInBackground];
}

Its pretty simple, i just lift the imagePointers array and get objectAtIndex0, then i cast it to a parse file.

But i can't do this in android, here is what i have atm:

    JSONArray imagePointers = thisStation.getJSONArray("imagePointers");
    try {
        JSONObject indexImage = imagePointers.getJSONObject(0);
    } catch ( Exception e ) {
        JSONObject indexImage = null;
    }

Here i get the object at index 0 as a JSONObject, i cannot use this in a ParseFile Object, since i need to cast it as a generic type ParseFile.

How do i do this? Or is my approach completely incorrect?

2 Answers 2

1

Fixed it by avoiding casting to JSON, apparently there is a getList method

    // Get parse Image as index image
    ParseObject thisStation = stationItems.get(position);
    List<ParseObject>imagePointers = thisStation.getList("imagePointers");
    ParseFile image = imagePointers.get(0).getParseFile("image");
    thumbnail.setParseFile(image);
    thumbnail.loadInBackground();
Sign up to request clarification or add additional context in comments.

Comments

0

I had the same issue for almost 2 days but finally I solved it by the getList method!

Now all you gotta do is use getList instead of getJSONObject or getJSONArray or whatever, because when you use them you will not be able to use the getParseFile for any of those believe me. But instead you can do something like:

val obj = parseObject.getList("listname")
val file = obj[0].getParseFile("image")

Now, I don't remember how the syntax is or so but the key here is to use the getList method if you want to get list of all images you saved in a Back4app Parse JSONArray.

Hope you found it helpful. Goodluck

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.