01: /*
02: * $Id: Test.java,v 1.1 2006/04/15 14:40:06 platform Exp $
03: * Created on 2006-4-15
04: */
05: package org.zkforge.json.simple;
06:
07: /**
08: * @author FangYidong<fangyidong@yahoo.com.cn>
09: */
10: public class Test {
11:
12: public static void main(String[] args) throws Exception {
13: JSONArray array1 = new JSONArray();
14: array1.add("abc\u0010a/");
15: array1.add(new Integer(123));
16: array1.add(new Double(122.22));
17: array1.add(new Boolean(true));
18: System.out.println("======array1==========");
19: System.out.println(array1);
20: System.out.println();
21:
22: JSONObject obj1 = new JSONObject();
23: obj1.put("name", "fang");
24: obj1.put("age", new Integer(27));
25: obj1.put("is_developer", new Boolean(true));
26: obj1.put("weight", new Double(60.21));
27: obj1.put("array1", array1);
28: System.out.println();
29:
30: System.out.println("======obj1 with array1===========");
31: System.out.println(obj1);
32: System.out.println();
33:
34: obj1.remove("array1");
35: array1.add(obj1);
36: System.out.println("======array1 with obj1========");
37: System.out.println(array1);
38: System.out.println();
39:
40: System.out.println("======parse to java========");
41:
42: String s = "[0,{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";
43: Object obj = JSONValue.parse(s);
44: JSONArray array = (JSONArray) obj;
45: System.out.println("======the 2nd element of array======");
46: System.out.println(array.get(1));
47: System.out.println();
48:
49: JSONObject obj2 = (JSONObject) array.get(1);
50: System.out.println("======field \"1\"==========");
51: System.out.println(obj2.get("1"));
52: }
53: }
|