Created
July 16, 2012 06:42
-
-
Save ucheng/3121142 to your computer and use it in GitHub Desktop.
Read String to JsonNode
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
package com.stanley; | |
import java.io.IOException; | |
import com.fasterxml.jackson.core.JsonProcessingException; | |
import com.fasterxml.jackson.databind.JsonNode; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import com.fasterxml.jackson.databind.ObjectReader; | |
public class ReadStringToJsonNode { | |
public static void main(String[] args) { | |
ObjectMapper mapper = new ObjectMapper(); | |
ObjectReader reader = mapper.reader(); | |
String jsonString = "{\"users\" : [{\"id\" : \"1\", \"name\" : \"stanley\", \"age\" : \"28\" }]}"; | |
try { | |
JsonNode node = reader.readTree(jsonString); | |
System.out.println(node.toString()); | |
} catch (JsonProcessingException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment