In the 'getAllRewards:
var reward = JSON.parse(object);
result = gameObj.app42.response.rewards.reward;
Possibly should have been:
var reward = JSON.parse(object);
result = reward.app42.response.rewards.reward;
and also the code didn't account for just one reward being present ie. result.length == undefined
in the end this worked:
rewardService.getAllRewards({
success: function (object) {
var reward = JSON.parse(object);
result = reward.app42.response.rewards.reward;
if (result.length == undefined) {
console.log(result.description);
console.log(result.name);
} else
for (var i = 0; i < result.length; i++) {
console.log(result[i].description);
console.log(result[i].name);
}
},
error: function (error) {
console.log(result[i].description);
}
});
Is this correct or have I just created other problems?
Also, in getRewardByName, the
console.log("rewardName is " + result.rewardName)
didn't work, but this did:
console.log("rewardName is " + result.name)