现在的位置: 首页 > 综合 > 正文

JSON相关操作

2013年07月22日 ⁄ 综合 ⁄ 共 343字 ⁄ 字号 评论关闭
net.sf.json.JSONArray
		String list = JSONArray.fromObject(inputList).toString();

com.google.gson.Gson
        Gson gson = new Gson();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("total", total);
		resultMap.put("rows", inputList);
		String resultList = gson.toJson(resultMap).toString();

以上两种将集合list转换为String的方式结果都一样:[{"id":"123","name":"rr"},{},{}]

抱歉!评论已关闭.