这是我的JSON数据Content.json
[{
status: "Allocated",
count: 45
}, {
status: "Bench",
count: 89
}, {
status: "Mobile",
count: 12
}, {
status: "Project",
count: 1
}, {
status: "SAP",
count: 18
}, {
status: "Testing",
count: 68
}, {
status: "vvvv",
count: 70
}];
试图获取那个JSON文件
angular.module('myApp')
.controller('valueController', ['$scope', '$http', '$window', function ($scope, $http, $window) {
var mainInfo = null;
$http({
method : "GET",
url : "/JSON/Content.json",
dataType: 'json',
}).then(function mySucces(response) {
$scope.mainInfo = response.data;
$window.alert(response.data);
}, function myError(response)
{
$window.alert(response.statusText);
});
$scope.chartOptions = {
dataSource: mainInfo,
series: {
argumentField: "status",
valueField: "count",
name: "SIDG Java",
type: "bar",
color: '#1899dd'
}
};
}]);
我得到了以下警告:
本地主机:8080说:
[{
status: "Allocated",
count: 45
}, {
status: "Bench",
count: 89
}, {
status: "Mobile",
count: 12
}, {
status: "Project",
count: 1
}, {
status: "SAP",
count: 18
}, {
status: "Testing",
count: 68
}, {
status: "vvvv",
count: 70
}];
我期待的是
本地主机:8080说:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],
发布于 2016-10-25 13:29:46
我通过实现您的代码在警报中获取对象、对象对象和对象。请再次检查JSON。
如果需要对象、对象结构,可以通过JSON.parse(response.data),解析数据。
发布于 2016-10-25 13:19:09
AngularJS可能无法在响应数据中检测到JSON。可能是响应中的Content-Type
头不是application/json
。
您可以尝试将dataType: 'json'
替换为$http
配置中的responseType: 'json'
,以告诉AngularJS预期JSON响应。
发布于 2016-10-25 13:15:56
若要在警报中显示,请将其转换为具有JSON.stringify函数的json字符串。
https://stackoverflow.com/questions/40240853
复制相似问题