96cba93fb7b111ec85869241b3069deff9122c8a.svn-base 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package samples.jsonTest;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import net.sf.json.*;
  7. public class Test {
  8. /**
  9. * @param args
  10. */
  11. private static boolean[] boolArray={true,false};
  12. private static List list = new ArrayList();
  13. private static Map map=new HashMap();
  14. private static Object[] test={new TestBean(),new TestBean()};
  15. public static void main(String[] args) {
  16. JSONArray jsonArray = JSONArray.fromObject( boolArray );
  17. //System.out.println(jsonArray.toString());
  18. JSONArray jsonArray1=JSONArray.fromObject("['1','2','3']");
  19. //System.out.println(jsonArray1.toString());
  20. list.add("first");
  21. list.add("second");
  22. //list.add(new TestBean());
  23. JSONArray jsonList = JSONArray.fromObject(list);
  24. System.out.println(jsonList);
  25. map.put("name", "windfree");
  26. map.put("bool", Boolean.TRUE);
  27. map.put("int",new Integer(0));
  28. map.put( "arr", new String[]{"a","b"} );
  29. map.put("func", "function (i){ return this.arr[i]; }");
  30. map.put("bean",test);
  31. JSONObject jsonMap = JSONObject.fromObject(map);
  32. System.out.println(jsonMap);
  33. JSONObject jsonBean=JSONObject.fromObject(new TestBean());
  34. System.out.println(jsonBean);
  35. }
  36. }