Created
December 10, 2022 15:03
-
-
Save dadhi/c29bafbb3e47ab8d14430a6e29145574 to your computer and use it in GitHub Desktop.
Java json parser with Jackson library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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