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 [0] .target' 배열을한다. 또한 결과가 JSON이고 문자열이 아닌지 확인하십시오 (그렇지 않은 경우 JSON.parse (result)를 사용하여 구문 분석하십시오). – mkaran
감사합니다. 배열 JSON을 놓친 사실이 있습니다. –