I'm a java developer, new to javascript and have a JSON string coming from a WebService that needs to be parsed in JavaScript
JSON String:
{
"myArrayList": [
{
"myHashMap": {
"firstName": "Clara",
"name": "Housing and Community Development"
}
},
{
"myHashMap": {
"firstName": "Nick",
"name": "Housing and Community Development"
}
}
]
}
I have tried the following to parse the data but always get 'undefined'. The webservice retrieves the text as above in string format.
$.getJSON("http://localhost:7001/WS/Users?Id=35",
function (jsonData)
{
for (var counter in jsonData.myArrayList) {
alert(jsonData.myArrayList[counter]['name'])
}
});
However the alert always displays 'undefined'. Any help on resolving this would be highly appreciated. Thanks.
myHashMapproperty. Alsofor...inis problematic with arrays if the order matters. You’re better off withforEachorfor...of.