1

响应

array (
    0 => 
    array (
      'time_start' => 1252652400,
      'time_stop' => 1252911600,
      'stats' => 
      array (
        6002306163363 => 
        array (
          'id' => 6002306163363,
          'impressions' => '6713',
          'clicks' => '7',
          'spent' => '593',
          'actions' => '1',
        ),
      ),
    ),
  )

数据显示在 rest/ads.getAdGroupStats 的 facebook api 中。

我无法将 stats 部分转换为 Java 类,其中 6002306163363 是一个变量,同样可以有更多的映射。以下是三个广告 123456、23456、34567 的完整结果。

[
  {
    "time_start": 0,
    "time_stop": 1285224928,
    "stats": {
      "123456": {
        "id": 123456,
        "impressions": 40,
        "clicks": 0,
        "spent": 0,
        "social_impressions": 0,
        "social_clicks": 0,
        "social_spent": 0
      },
      "23456": {
        "id": 23456,
        "impressions": 3,
        "clicks": 0,
        "spent": 0,
        "social_impressions": 0,
        "social_clicks": 0,
        "social_spent": 0
      },
      "34567": {
        "id": 34567,
        "impressions": 211457,
        "clicks": 84,
        "spent": 6898,
        "social_impressions": 124,
        "social_clicks": 0,
        "social_spent": 0
      }
    }
  }
]

我必须创建一个 Java 类,它可以映射到上面的 JSON 并且不能这样做。任何人都可以在这里帮助我吗?

更新:我从 facebook 和我们使用的 api 中获取这些数据需要类,以便可以映射返回的 json。我只能控制创建一个类,以便 api 在内部将其映射出来。我需要所需的java类的格式。

4

2 回答 2

1

我是 Mark Allen(RestFB 维护者)。1.6 版应该使用映射到内置 JsonObject 类型的新选项来解决这个问题 - 请查看http://restfb.com以获取示例。

于 2011-01-05T19:18:24.603 回答
1

您需要一个哈希图或类似的东西来处理这些数字键。

public class GroupStats {
   long time_start;
   long time_stop;
   HashMap<GroupAccount> stats;
}

public class GroupAccount {
   long id;
   int impressions;
   int clicks;
   int spent;
   int social_impressions;
   int social_spent;
}
于 2010-09-23T08:54:12.573 回答