后台将map放入jsonobject中,前台从map中取值; JsonObject转map
//后台 Map<String, Object> map = new HashMap<String, Object>(); map.put("result", 1); map.put("count", count); JSONObject json = JSONObject.fromObject(map); response.getWriter().print(json.toString());// //前台 用net.sf.json.JSONObject将java.util.Map封装后,使用javascript获取的方法: 在ajax success:function(json) { var map=eval('('+json+')');//用eval函数将json转化为对象 //然后就可以通过map.key获取对应的value alert(map.result); alert(map.count); }
//遍历jsonobject,转换为map
JSONObject joContent = new JSONObject(content); Map targetMap= new HashMap<>(); for (Iterator iter = joContent.keys(); iter.hasNext();) { String key = (String) iter.next(); targetMap.put(key, joContent.get(key)); }
相关推荐
WebVincent 2020-07-21
fengchao000 2020-07-04
baijinswpu 2020-06-28
88483063 2020-06-28
fengchao000 2020-06-16
somebodyoneday 2020-06-15
wujiajax 2020-06-14
somebodyoneday 2020-05-16
xx0cw 2020-05-16
newthon 2020-05-14
sailxu00 2020-04-27
fengchao000 2020-04-20
88483063 2020-01-29
83163452 2020-01-28
baijinswpu 2020-01-25
baijinswpu 2020-01-18