Created
February 16, 2015 11:06
-
-
Save uttesh/ab9c219f31f6eaa95d3e to your computer and use it in GitHub Desktop.
Using org.codehaus.jackson read json string
This file contains hidden or 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 java.util.HashMap; | |
import java.util.Map; | |
import org.codehaus.jackson.map.ObjectMapper; | |
import org.codehaus.jackson.type.TypeReference; | |
/** | |
* | |
* @author Rivet Systems | |
*/ | |
public class JSONReader { | |
public static void main(String[] args) { | |
String json = "{\"name\":\"Uttesh\", \"blog\":\"uttesh.blogspot.com\"}"; | |
Map<String, String> map = new HashMap<String, String>(); | |
ObjectMapper mapper = new ObjectMapper(); | |
try { | |
//convert JSON string to Map | |
map = mapper.readValue(json, | |
new TypeReference<HashMap<String, String>>() { | |
}); | |
System.out.println(map); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment