0

Context : Json,Jquery,Java

The json object like this :

[{"7818.0":".NET Developer"},{"6124.0":".Net Off Shore Support Project Manager"},{"6125.0":".Net Off Shore Support Project Member"},{"6922.0":"2 APAC Inventory Orgs Under SPSW Manager"}]

The code in Jquery :

var roles = <%=request.getAttribute("roleList")%>
$.each(roles, function(object) {
                //display the key and value pair
                alert(object.key);
                alert(object.value);
            });

Any suggestions is really appreciated

Sachin Gupta
  • 7,805
  • 4
  • 30
  • 45

1 Answers1

0

You can change your code to :

$.each(roles, function(key,value) {
   for (var i in value) {
      alert("Key: "+i);
      alert("Value: "+value[i]);
   }                 
});

get the key and value from the map.

Here's the working fiddle: https://jsfiddle.net/pr21ojof/

Akash Rajbanshi
  • 1,553
  • 11
  • 23