2013-08-22 55 views

回答

1

使用JSONObjectnet.sf.json.JSONObject類是這樣的:

JSONObject jsonObject=new JSONObject(); 

JSONObject childObject=new JSONObject(); 
childObject.put("class", "group"); 
childObject.put("text", "test1"); 

jsonObject.put("1", childObject); 
jsonObject.put("2", childObject); 

System.out.println(jsonObject.toString()); 
+0

我寫了類似的路線,但是有錯誤 childNode.put( 「類」 ,element.className()); childNode.put(「text」,element.ownText()); group.put(i,childNode); 因爲「我」是一個整數,如何解決它? – hkguile

+0

已修復。謝謝 .... – hkguile