java中gson是什么_在Java中使用GSON解析复杂的Json对象

我有一个很长的JSON与Gson一起解析,但是为了简洁起见,我将其修剪为以下示例:

{

"volumes": [

{

"status": "available",

"managed": true,

"name": "va_85621143-1133-412f-83b4-57a01a552638_",

"support": {

"status": "supported"

},

"storage_pool": "pfm9253_pfm9254_new",

"id": "afb8e294-6188-4907-9f6f-963c7623cecb",

"size": 9

},

{

"status": "in-use",

"managed": false,

"name": "bt_newd20",

"support": {

"status": "not_supported",

"reasons": [

"This volume is not a candidate for management because it is already attached to a virtual machine. To manage this volume with PowerVC, select the virtual machine to which the volume is attached for management. The attached volume will be automatically included for management."

]

},

"storage_pool": "KVM",

"mapped_wwpns": [

"2101001B32BD4280",

"2100001B329D4280",

"2101001B32BD637E",

"2100001B329D637E"

],

"id": "c7838c79-17ca-3cbc-98e5-3567fde902d8",

"size": 0

},

{

"status": "available",

"managed": true,

"name": "vdisk138",

"support": {

"status": "supported"

},

"storage_pool": "Chassis2_IBMi",

"id": "b6d00783-9f8c-40b8-ad78-956b0299478c",

"size": 100

}

]

}

从SO和其他几个地方,我发现我需要定义一个顶级容器,例如下面的容器,但我不知道如何完成其​​定义

static class VolumeContainer {

//I don't know what do in here. This is the first problem

}

然后每堂课 Volume

static class Volume {

private String status;

private boolean managed;

private String name;

//This is the second problem.The "support" variable should not be a string.

//It is in {}. Just for information, I won't use it.

//private String support;

private String storagePool;

private List mapped_wwpns;

private String id;

private String size;

}

我正在尝试解析它,这是到目前为止我编写的代码:

JsonParser parser = new JsonParser();

JsonObject obj = parser.parse(response).getAsJsonObject();

Gson gson = new Gson();

JSON字符串存储在名为response的变量中

VolumeContainer vc = gson.fromJson(response,VolumeContainer.class);

我的最终要求是HashTableof,id并且关联name。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值