我在json对象中获得了动态的密钥数量,它将根据我使用的改造数据进行更改
JSON
{
"response_message": "Settings has been displayed successfully",
"deliveryCharges": [
{
"iSettingId": 2,
"vSettingDescription": "deliveryCharges",
"vSettingName1": 1,
"vSettingName2": 1.5,
"vSettingName3": 1.75,
.
.
.
"vSettingNamen": 1.75
},
{
"iSettingId": 3,
"vSettingDescription": "deliveryCharges",
"vSettingName1": 1,
"vSettingName2": 1.5,
"vSettingName3": 1.75,
.
.
.
"vSettingNamen": 1.75
},
{
"iSettingId": 4,
"vSettingDescription": "deliveryCharges",
"vSettingName1": 1,
"vSettingName2": 1.5,
"vSettingName3": 1.75,
.
.
.
"vSettingNamen": 1.75
}
]
}
这里我可以获得n个vSettingName。它是完全动态的,所以我怎样才能为此制作POJO
答案 0 :(得分:1)
试试这个
Gson gson = new Gson();
Type mapType = new TypeToken<List<Map<String, String>>>(){}.getType(); //define generic type
List<Map<String, String>> result = gson.fromJson(deliveryCharges,mapType);