1String message;
2JSONObject json = new JSONObject();
3json.put("name", "student");
4
5JSONArray array = new JSONArray();
6JSONObject item = new JSONObject();
7item.put("information", "test");
8item.put("id", 3);
9item.put("name", "course1");
10array.add(item);
11
12json.put("course", array);
13
14message = json.toString();
15
16// message
17// {"course":[{"id":3,"information":"test","name":"course1"}],"name":"student"}
1import org.json.simple.JSONObject;
2
3class JsonEncodeDemo {
4
5 public static void main(String[] args) {
6 JSONObject obj = new JSONObject();
7
8 inputJSON.put("subscriberName", "subscriber");
9 inputJSON.put("msisdn","7055389495");
10
11 System.out.print(obj);
12 }
13}
1JSONObject jsonObject = //...
2JsonNode jsonNode = convertJsonFormat(jsonObject);
3ObjectMapper mapper = new ObjectMapper();
4MyPojoClass myPojo = mapper.readValue(new TreeTraversingParser(jsonNode), MyPojoClass.class);