2014-10-04 53 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();