I am working on SpringMVC. In my controller I create a JSON object and I pass that object to JavaScript. How can I read that object in JavaScript?
My Map
object
Map<String rootNode,List<String>> map = new HashMap<String rootNode,List<String>();
String rootNode = "bhanu";
ArrayList<String> al = new ArrayList<String>();
for( int i = 0; i < UserProfile.size; i++ ) {
al.add( userProfile.get( i ) );
}
map.put( userProfile, al );
At last my Map
object has this data:
{
"Bhanu":["hari@gmail.com","balu@gmail.com","santha@gmail.com"],
"root":["bhanu@gmail.com","anu@gmail.com","apar@gmail.com"],
"hari":["bhanuprasad@gmail.com","sravya@gmail.com","mahesh@gmail.com"],
"balu":["rama@gmail.com"]
}
Now I convert this object with GSon
:
Gson gson = new GSon();
String orgChartUsers = gson.toJson(map);
Now I passed this string to JavaScript because this is my Ajax response:
function orgUsers( result ) {
var orgObject = JSON.parse( result );
for(var name in result) {
console.log(name + "=" + result[name]);
}
}
This is working fine but i want to fetch data like this first i want to fetch data from "root" in root i have some data when i read root for example i got bhanu@gmail.com now i want to fetch the data from Bhanu here i got some data like hari@gmail.com again i want to fetch data for hari like this i want how can i do this any one help me