RestFB错误地将许多对象解析为一个

时间:2013-06-30 18:20:47

标签: facebook facebook-graph-api restfb

我的restFB代码导致在一个App上写入我的ArrayList。我需要arraylist正确填写JSON中的appIds返回数。任何见解?

这是我的代码:

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"
   }
}

1 个答案:

答案 0 :(得分: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;
}