JSON応答にアクセスしようとしましたが、オブジェクトにアクセスできません。サービス内のオブジェクトにアクセスできません
私はtarget
とdatapoint
のオブジェクトを取得する必要があり、その後はdataPoint
の配列を繰り返す必要があります。
result.target
は、上記の場合は不定です。
コントローラ:私は受け付けておりますことを
$scope.serviceCalls = function() {
var serviceUrl = "http://localhost:8080/rest/1";
var promise = CommonService.getServiceJSON(serviceUrl);
promise.then(function(result) {
$scope.jsondata = result;
console.log($scope.jsondata); // getting the JSON in console logs
console.log($scope.jsondata.target); //returns undefined
}, function(reason) {
alert('Failed: ' + reason);
}, function(update) {
alert('Got notification: ' + update);
});
}
JSONレスポンス:
[{
"target": "xxxxxxxxxxxx",
"datapoints": [
[14711037952.0, 1474340220],
[14711058432.0, 1474340280],
[14719434752.0, 1474361700],
[null, 1474361760]
]
}]
'$のscope.jsondataあります。また、結果がJsonであり、文字列でないことを確認してください(それ以外の場合はJSON.parse(result)を使用して解析してください) – mkaran
ありがとうございます。 私はその配列JSONを見逃しています。 –