1、使用Gson将String(json)转换成bean:
String data = bundle.getString("cardData"); Gson gson = new Gson(); CheckOrderBean orderBean = gson.fromJson(data, CheckOrderBean.class);
2、将bean对象转换为json字符串
BonusBean bean = orderBean.getData().getBonus();
String cardStr = gson.toJson(bean, BonusBean.class)
3、JSON转换为Map:
Map<String, CheckOrderBean.DataBean.BonusBean._$72522Bean> cardMap = gson.fromJson(cardStr, new TypeToken<Map<String, CheckOrderBean.DataBean.BonusBean._$72522Bean>>() {}.getType());
4、Map转List:
Map<String, String> testMap = orderBean.getData().getBonus();
List<CheckOrderBean.DataBean.BonusBean._$72522Bean> list = new ArrayList(); Iterator iter = testMap.entrySet().iterator(); // 获得map的Iterator while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); CheckOrderBean.DataBean.BonusBean._$72522Bean bean = (CheckOrderBean.DataBean.BonusBean._$72522Bean)entry.getValue(); list.add(bean); }