Skip to content

Instantly share code, notes, and snippets.

@dadhi
Created December 10, 2022 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadhi/c29bafbb3e47ab8d14430a6e29145574 to your computer and use it in GitHub Desktop.
Save dadhi/c29bafbb3e47ab8d14430a6e29145574 to your computer and use it in GitHub Desktop.
Java json parser with Jackson library
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JsonParserIterator {
public static void main(String[] args) throws IOException {
String json = "{ \"fx\": [{ \"pk\": \"ALL=\" }, { \"pk\": \"EUR=\" }] }";
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(json);
Iterator<JsonNode> elements = root.get("fx").elements();
while (elements.hasNext()) {
JsonNode element = elements.next();
String pk = element.get("pk").asText();
System.out.println(pk);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment