我使用jackson库从Json反序列化。我需要从这个json中提取2个值,即c1和d1。我使用过这段代码......我需要知道克服获取c1和d1值的正确方法......
我的json
{"Alpha":{"A":{"B":{"C":{"c1":1234,c2:"abcd"},"D":{"d1":"xyz","d2":5678,"d3":"qwerty"},"E":[{"e1":456,"e2":"mnop"},{"e1":098,"e2":"qrst"}]}}},"X"{"x1":8098}}
ObjectMapper mapper = new ObjectMapper();
mainclass alphaobj = mapper.readValue(new File("C:\\employee.json"), mainclass.class);
System.out.println(alphaobj.A.B.C.getc1());
答案 0 :(得分:1)
也许你应该使用杰克逊Tree Model代替?
类似的东西:
JsonNode root = mapper.readTree(file);
int c1 = root.path("Alpha").path("A").path("C").path("C1").intValue();
等等。