2013-06-30 53 views
0

我的restFB代碼導致在一個App上寫入我的ArrayList。我需要arraylist才能正確填寫JSON中返回的appIds數量。任何見解?RestFB將許多對象解析爲一個不正確

這裏是我的代碼:

public List<String> fetchAppIdsForUser() { 
    Connection<FacebookApp> appList = getClient().fetchConnection("me/applications/developer", FacebookApp.class); 

    List<String> appIds = new ArrayList<String>(); 
    for (List<FacebookApp> appListTwo : appList) { 
      for (FacebookApp app : appListTwo) { 
      appIds.add(app.getAppId()); 
      } 
    } 

    return appIds; 
} 

這裏是什麼是JSON返回:

{ 
    "data": [ 
     { 
     "name": "x", 
     "namespace": "x", 
     "id": "x" 
     }, 
     { 
     "name": "xx", 
     "namespace": "xx", 
     "id": "xx" 
     }, 
     { 
     "name": "xxx", 
     "namespace": "xxxx", 
     "id": "xxxxx" 
     }, 
     { 
     "name": "xxxx", 
     "namespace": "xxxxx", 
     "id": "xxxxx" 
     } 
    ], 
    "paging": { 
     "next": "https://graph.facebook.com/xxxxx/applications?type=developer&format=json&access_token=XXXXXXXX" 
    } 
} 

回答

0

我解決它使用下列內容:

public List<String> fetchAppIdsForUser() { 
    Connection<FacebookApp> appList = getClient().fetchConnection("me/applications/developer", FacebookApp.class); 
    List<FacebookApp> list = appList.getData(); 
    ArrayList<String> appNames = new ArrayList<String>(); 
    for (FacebookApp app: list) { 
     appNames.add(app.getName()); 
    }  
    return appNames; 
}