public static void testJava(){
Map m1 = new HashMap();
m1.put("Zara", "8");
m1.put("Mahnaz", "31");
m1.put("Ayan", "12");
m1.put("Daisy", "14");
System.out.println();
System.out.println(" Map Elements");
System.out.print("\t" + m1);
if (m1.containsKey("Mahnaz")) {
System.out.println(m1.get("Mahnaz"));
}
if (m1.get("Mahnaz").equals("31")) {
System.out.println("xxxxx");
}
/* ------------------------- */
List<String> cellList1=new ArrayList<>();
cellList1.add("aa");
cellList1.add("bb");
Map<String,Object> module1=new HashMap<>();
module1.put("code","04XMEXAXD10MG19800000010");
module1.put("cellList",cellList1);
List<Map<String,Object>> moduleList1=new ArrayList<>();
moduleList1.add(module1);
System.out.println("moduleList1=" + moduleList1);
/* ----------- 来自send()函数 -------------- */
Map<String, Object> requestMap2 = new HashMap<String, Object>();
String requestMsg = new JsonSerializer().deep(true).serialize(moduleList1);
System.out.println("requestMsg=" + requestMsg);
String data = "[{a:b}]";
String flag = "";
/* ------------ 来自test 或 send()函数 ------------- */
Map<String, Object> requestMap = new HashMap<String, Object>();
requestMap.put("p1", data);
requestMap.put("p2", System.currentTimeMillis());
requestMap.put("p3", flag);
System.out.println("requestMap=" + requestMap);
/* ----------- 来自 getRequest()函数 -------------- */
try {
String string2 = (new JsonSerializer()).serialize(requestMap);
System.out.println("string2=" + string2);
/* ----------- 来自test 或 parsToMap()函数 -------------- */
ObjectMapper mapper = new ObjectMapper();
Map map = mapper.readValue(string2, Map.class);
String result=map.get("p2").toString();
System.out.println("result=" + result);
if(isNotEmpty(map.get("p3"))){
System.out.println("returnstring=" + map.get("p3").toString());
}else {
System.out.println("returnstring=" + map.get("p3").toString());
}
/* ----------- 来自receivedata()函数 -------------- */
String packList = "{'code': 5}";
JSONObject jsonObject = JSONObject.parseObject(packList);
//Map<String, String> params = JSONObject.parseObject(jsonObject.toString(), new TypeReference<Map<String, String>>(){});
Map<String, Object> params = JSONObject.parseObject(jsonObject.toString(), new TypeReference<Map<String, Object>>(){});
System.out.println(params.get("code"));
}catch (Exception e){
e.printStackTrace();
}
}
它的运行结果会是
Map Elements
{Daisy=14, Ayan=12, Zara=8, Mahnaz=31}31
xxxxx
moduleList1=[{code=04XMEXAXD10MG19800000010, cellList=[aa, bb]}]
requestMsg=[{"code":"04XMEXAXD10MG19800000010","cellList":["aa","bb"]}]
requestMap={p1=[{a:b}], p2=1617690850558, p3=}
string2={"p1":"[{a:b}]","p2":1617690850558,"p3":""}
result=1617690850558
returnstring=
5