import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
8
class Program5 {
10
11 12 13 14 15 16 HashMap<String,Object> map =
new HashMap<String,Object>
();
17 map.put("key1","value1"
);
18 map.put("key2","value2"
);
19
20 HashMap<String,Object> map2 =
21 map2.put("key1",1
);
22 map2.put("key2",2
);
23
24 HashMap<String,Object> map3 =
25 Person person1 =
26 person1.setAge(32
);
27 person1.setName("wangyunpeng"
);
28 map3.put("wyp"
,person1);
29 Person person2 =
30 person2.setAge(17
);
31 person2.setName("shenyunxiao"
);
32 map3.put("shyx"
,person2);
33
34 List<HashMap<String,Object>> list =
new ArrayList<HashMap<String,Object>>
();
35 list.add(map);
36 list.add(map2);
37 list.add(map3);
38
39 String json =
FastJSONHelper.serialize(list);
40 System.out.println(json);
41
42 list =
FastJSONHelper.deserializeAny(json,43 new TypeReference<List<HashMap<String,Object>>>
() {
44 });
45 for (HashMap<String,Object>
item : list) {
46 for (Map.Entry<String,Object>
entry : item.entrySet()) {
47 String key =
entry.getKey();
48 Object value =
entry.getValue();
49 if (value
instanceof JSONObject) {
50 JSONObject jObj =
(JSONObject) value;
51 String json2 =
FastJSONHelper.serialize(jObj);
52 Person other = FastJSONHelper.deserialize(json2,128); line-height:1.5!important">53
System.out.println(String.format(
54 "Key:
%s,Value:[Name:
%s,Age:
%s]"
,key,128); line-height:1.5!important">55 other.getName(),other.getAge()));
56 }
else {
57 Sy
stem.out.println(String.format("Key:
%s,Value:
%s"
,128); line-height:1.5!important">58 value));
59 }
60 }
61 }
62
63 }
64
65 }