2014-10-04 26 views
0

我遇到了一個問題,同時將我的iOS應用程序轉換爲android。通用ParseFile對象的JSON對象,問題

數據庫的結構使得有「站點」,這些站點可以有多個附加的圖像,在解析數據庫中,圖像是一個imagePointers數組。

當我希望得到這些圖片,iOS中這裏是我做過什麼:

站=在這種情況下,對象

// 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]; 
} 

它很簡單,我只是舉imagePointers陣列,並得到objectAtIndex0 ,然後我把它轉換成一個解析文件。

但我不能在Android中做到這一點,這裏是我有個大氣壓:

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

這裏我得到的對象在索引0作爲一個JSONObject,我不能在ParseFile對象使用,因爲我需要把它作爲一個泛型類型ParseFile。

我該怎麼做?或者我的方法完全不正確?

回答

0

通過避免鑄造JSON固定它,顯然存在的GetList方法

// 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();