日期:2014-05-16 浏览次数:20388 次
JSONUtil.object2JSON(object,stringBuffer,new Class[]{...});
JSONUtil.object2JSON(object,stringBuffer)
WordType wt = new WordType(); wt.setName("f"); wt.setId(3); Word w = new Word(); w.setName("a"); w.setType(wt); JSONUtil.object2JSON(w,stringBuffer,new Class[]{WordType.class});
Word:{"name":"a","type":{"id":3,"name":"f"}}
Tag t = new Tag(); t.setName("t"); Tag tt = new Tag(); tt.setName("tt"); Tag[] ttt = {t,tt}; WordType wt = new WordType(); wt.setName("f"); wt.setId(3); Word w = new Word(); w.setName("a"); w.setType(wt); w.setTags(ttt); WordType wtt = new WordType(); wtt.setName("gg"); wtt.setId(2); Word ww = new Word(); ww.setName("aa"); ww.setType(wtt); ww.setTags(new Tag[]{t}); List<Tag> tagList = new ArrayList<Tag>(); tagList.add(t); tagList.add(tt); ww.setTagList(tagList); JSONUtil.object2JSON(new Word[]{w,ww},stringBuffer,new Class[]{WordType.class,Tag.class});
[Word:{"name":"a","tags":[{"name":"t"},{"name":"tt"}],"type":{"id":3,"name":"f"}},Word:{"name":"aa","tagList":[{"name":"t"},{"name":"tt"}],"tags":[{"name":"t"}],"type":{"id":2,"name":"gg"}}]
LangObject lo = new LangObject(); lo.setBooleanValue(true); lo.setByteValue(Byte.valueOf("2")); lo.setCharacterValue(Character.valueOf('3')); lo.setDoubleValue(4.0); lo.setFloatValue(5f); lo.setIntegerValue(6); lo.setLongValue(7l); lo.setShortValue(Short.valueOf("8")); lo.setBooleanObject(true); lo.setByteObject(Byte.valueOf("2")); lo.setCharacterObject(Character.valueOf('3')); lo.setDoubleObject(4.0); lo.setFloatObject(5f); lo.setIntegerObject(6); lo.setLongObject(7l); lo.setShortObject(Short.valueOf("8")); lo.setUtilDate(new java.util.Date()); lo.setSqlDate(java.sql.Date.valueOf("2009-6-6")); JSONUtil.DATE_FORMAT = "yyyy/MM/dd"; JSONUtil.object2JSON(lo,stringBuffer);
LangObject:{"booleanObject":"true","booleanValue":"true","byteObject":2,"byteValue":2,"characterObject":"3","characterValue":"3","doubleObject":4.0,"doubleValue":4.0,"floatObject":5.0,"floatValue":5.0,"integerObject":6,"integerValue":6,"longObject":7,"longValue":7,"shortObject":8,"shortValue":8,"sqlDate":"2009/06/06","utilDate":"2009/06/12"}