String jsonStr = "{'a':'b','c':'d'}";
JSONObject obj = (JSONObject) JSON.parse(jsonStr);
String bStr = (String) obj.get("a");
System.out.println(bStr);
以下为JSON的list格式转为JAVA的list对象
String attachMentsStr = jsonObj.getString("attachMentVOs");
List<AttachMentVO> attachMentsList = new ArrayList<AttachMentVO>();
JSONArray attachMents = JSONArray.parseArray(attachMentsStr);
for(int i=0;i<attachMents.size();i++){
AttachMentVO attachMentVO = new AttachMentVO();
attachMentVO.setAttName(((JSONObject) attachMents.get(i)).getString("attName"));
attachMentVO.setAttPath(((JSONObject) attachMents.get(i)).getString("attPath"));
attachMentVO.setMemo(((JSONObject) attachMents.get(i)).getString("memo"));
attachMentsList.add(attachMentVO);
}
System.out.println(attachMentsList.get(0).getAttPath());
以下为对象转JSON格式的字符串
JSON.toJSONString(Obj);
JSONArray.toJSONString(object);