I'm using Java, and I have a String which is JSON:
{
"name" : "abc" ,
"email id " : ["abc@gmail.com","def@gmail.com","ghi@gmail.com"]
}
Then my Map in Java:
Map<String, Object> retMap = new HashMap<String, Object>();
I want to store all the data from the JSONObject in that HashMap.
Can anyone provide code for this? I want to use the org.json
library.
You can convert any
JSON
tomap
by using Jackson library as below:Maven Dependencies for Jackson :
Hope this will help. Happy coding :)
You can use Jackson API as well for this :
If you hate recursion - using a Stack and javax.json to convert a Json String into a List of Maps:
Here is Vikas's code ported to JSR 353:
I wrote this code some days back by recursion.
Using GSon, you can do the following: