123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package samples.jsonTest;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import net.sf.json.*;
- public class Test {
- /**
- * @param args
- */
- private static boolean[] boolArray={true,false};
- private static List list = new ArrayList();
- private static Map map=new HashMap();
- private static Object[] test={new TestBean(),new TestBean()};
- public static void main(String[] args) {
-
- JSONArray jsonArray = JSONArray.fromObject( boolArray );
- //System.out.println(jsonArray.toString());
- JSONArray jsonArray1=JSONArray.fromObject("['1','2','3']");
- //System.out.println(jsonArray1.toString());
-
- list.add("first");
- list.add("second");
- //list.add(new TestBean());
- JSONArray jsonList = JSONArray.fromObject(list);
- System.out.println(jsonList);
-
- map.put("name", "windfree");
- map.put("bool", Boolean.TRUE);
- map.put("int",new Integer(0));
- map.put( "arr", new String[]{"a","b"} );
- map.put("func", "function (i){ return this.arr[i]; }");
- map.put("bean",test);
- JSONObject jsonMap = JSONObject.fromObject(map);
-
- System.out.println(jsonMap);
- JSONObject jsonBean=JSONObject.fromObject(new TestBean());
-
-
- System.out.println(jsonBean);
- }
- }
|