English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
JiaJsonNode is the base class for all JSON nodes forming the JSON tree modelArrayNode is a node class that represents an array mapped from JSON content. We can use}}ObjectMapper classreadTree()method andget()Method to access the value of the specified element in the array node, by casting to ArrayNode to retrieve the value, isJsonNodeConvert or convert to ArrayNode.
public JsonNode readTree(String content) throws IOException, com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.core.JsonProcessingException; public class JsonNodeToArrayNodeTest { public static void main(String args[]) throws JsonProcessingException { String jsonStr = "{\"Technologies\": [\"Java\", \"Scala\", \"Python\"]}"; ObjectMapper mapper = new ObjectMapper(); ArrayNode arrayNode = (ArrayNode) mapper.readTree(jsonStr).get("Technologies"); if(arrayNode.isArray()) { for(JsonNode jsonNode : arrayNode) { System.out.println(jsonNode); } } } }
Output Result
"Java" "Scala" "Python"