从上一篇得到properties里的数据
1 Map<String,String> map = new HashMap<String,String>(); 2 Enumeration<Object> keys = properties.keys(); 3 while(keys.hasMoreElements()){ 4 String key = (String)keys.nextElement(); 5 String value = (String)properties.get(key); 6 map.put(key,value); 7 }
现在得到了properties里的数据,然后怎样转化为json?我用的是用Gson转化,看以下内容吧
1 Gson gson = new Gson(); 2 String jsonStr = gson.toJson(map); 3 //以下是传输到调用页面
4 PrintWriter pw = response.getWriter(); 5 pw.print(jsonStr); 6 pw.flush();