I am trying to print out the key and value names from the data below e.g. "Player 1' - 'ball' 'hat' and "Player 2 - 'ball, 'hat'. So keys have multiple value names but im not sure how i print these out.** I am getting '[object Object]' as a response**. Can someone help me with this understanding please and trying to resolve the matter.
Data
{
"Player1": {
"ball": 1,
"hat": 2
},
"Player2": {
"ball": 1,
"hat": 2,
}
}
JavaScript
$.getJSON('data.json', function (data) {
var response = data;
for (key in response){
alert("key: " + key + "value :" + response[key]);
}
});
console.log("key:", key, "value:", response[key]); it'll allow you to see the objects, regardless of whether you stringify them.