如何为一个JSON字符串创建一个java类,其中key是可变的? [英] How to create a java class for a JSON string where keys are variable?

查看:116
本文介绍了如何为一个JSON字符串创建一个java类,其中key是可变的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

响应

  array(
0 =>
array(
' time_start'=> 1252652400,
'time_stop'=> 1252911600,
'stats'=>
数组(
6002306163363 =>
数组b $ b'id'=> 6002306163363,
'impressions'=>'6713',
'clicks'=>'7',
'spend'=& 593',
'actions'=>'1',
),
),
),

数据显示在facebook的休息/ ads.getAdGroupStats中。



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

  [
{
time_start :0,
time_stop:1285224928,
stats:{
123456:{
id:123456,
40,
点击:0,
已用:0,
social_impressions:0,
social_clicks:0,
social_spent 0
},
23456:{
id:23456,
印象:3,
点击:0,
0,
social_impressions:0,
social_clicks:0,
social_spent:0
},
34567
id:34567,
印象:211457,
点击:84,
已花费:6898,
social_impressions
social_clicks:0,
social_spent:0
}
}
}
]
我必须m。$ / pre>

ake一个可以映射到上述JSON的Java类,不能这样做。任何人都可以帮助我吗?



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

解决方案

我是Mark Allen(RestFB维护者)。版本1.6应该使用新的选项映射到内置的JsonObject类型 - 请查看 http://restfb.com 为例。


The response

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

data is shown in facebook api of rest/ads.getAdGroupStats.

I am not able to convert the stats part to a Java class, Where the 6002306163363 is a variable and similarly could have many more mappings. Below is the full result for three ads 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
      }
    }
  }
]

I have to make a Java class which could map to the above JSON and not able to do so. Can anyone please help me here?

Update : I am getting this data from facebook and in the api that we are using requires class, so that the returned json could be mapped. I have only control to create a class so that api internally map this out. I need the format of the java class required.

解决方案

I'm Mark Allen (RestFB maintainer). Version 1.6 should address this with the new option to map to the built-in JsonObject type - check out http://restfb.com for an example.

这篇关于如何为一个JSON字符串创建一个java类,其中key是可变的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆