使用Jackson和JsonNode
,你会怎么做:
private static final ObjectReader READER = new ObjectMapper()
.getReader;
// blah
// read the node
final JsonNode node = READER.readTree(fromWhatever);
// access the inner "files" member
final JsonNode filesNode = node.get("files");
访问内部对象。
然后走filesNode
对象,你会怎么做:
final Iterator<Map.Entry<String, JsonNode>> iterator = filesNode.fields();
Map.Entry<String, JsonNode> entry;
while (iterator.hasNext()) {
entry = iterator.next();
// the "inval" field is entry.getValue().get("inval")
}
如果你可以使用这个this project变得更加简单:
// or .fromFile(), .fromReader(), others
final JsonNode node = JsonLoader.fromString(whatever);
final Map<String, JsonNode> map = JacksonUtils.nodeToMap(node.get("files"));
// walk the map
来源
2013-06-12 10:24:25
fge
您确定您的意思是Java? – NimChimpsky
有JSON库可以做到这一点。 – NINCOMPOOP