(java) Java Jackson JsonNode 的get(i)方法疑惑

 String str = "{"data":{"birth_day":7,"birth_month":6},"errcode":0,"msg":"ok","ret":0}"; ObjectMapper mapper = new ObjectMapper; JsonNode root = mapper.readTreestr; for int i = 0; i < root.size ; i++ { System.out.printlnroot.geti; } for Iterator<?> iter = root.fieldNames;iter.hasNext;{ System.out.printlniter.next; }

// null
// null
// null
// null
// data
// errcode
// msg
// ret


public JsonNode getint index

Method for accessing value of the specified element of an array node. For other nodes, null is always returned.

For array nodes, index specifies exact location within array and allows for efficient iteration over child elements underlying storage is guaranteed to be efficiently indexable, i.e. has random-access to elements. If index is less than 0, or equal-or-greater than node.size, null is returned; no exception is thrown for any index.





电子邮件地址不会被公开。 必填项已用*标注