如何创建具有动态密钥的pojoclass [英] How to create a pojoclass having dynamic key

查看:137
本文介绍了如何创建具有动态密钥的pojoclass的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从同一个url的下面的响应创建一个pojo类。



回复1:
{
info:{
price:1,
map:{
1:1,
2:2,
3:1,
5:0.5,
6:3,
7:5
},
值:0
}


$ p
$ price $ 1






$地图:{
1:1,
2:6,
3:4,
},
值:1
}
}



这里mapJson对象内的键是动态的。请帮我用动态键创建一个pojoclass(内部映射例如:1,2,3 ...)。

解决方案

最后通过使用

 私人地图< String,Float>地图; 

public Map< String,Float> getMap(){
return map;

内部POJO类。

我在内部调用POJO Activity by

  Map< String,Float> maps = POJOclass.getMap(); 
for(String mapKey:maps.keySet()){
Log.d(Map,mapKey:+ mapKey +,mapValue:+ maps.get(mapKey)):
}


How can i create a pojo class from the below responses of same url.

RESPONSE 1: { "info": { "price": 1, "map": { "1": 1, "2": 2, "3": 1, "5": 0.5, "6": 3, "7": 5 }, "value": 0 } }

RESPONSE 2: { "info": { "price": 1, "map": { "1": 1, "2": 6, "3": 4, }, "value": 1 } }

here the keys inside the "map" Json object is dynamic. Please help me to create a pojoclass with dynamic key(inside map eg:1,2,3...).

解决方案

Finally got my answer by using

private Map<String, Float> map;

public Map<String, Float> getMap() {
return map;
}

inside POJO class.

And i called the POJO inside Activity by

Map<String, Float> maps =POJOclass.getMap();
for (String mapKey :  maps.keySet()) {
Log.d("Map","mapKey : "+mapKey+" , mapValue : "+maps.get(mapKey)):
}

这篇关于如何创建具有动态密钥的pojoclass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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