如何在angularJS中以对象形式解析AJAX Json数据
How can I parse AJAX Json data in object form in angularJS
这是我的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'
}
};
}]);
在alert中我得到:
Localhost: 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
}];
我期待的是
Localhost: 8080说:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],
通过实现代码,我在警报中获得[object,object][object,object][object,object]。请再次检查JSON。
如果需要使用[object,object]结构
有可能AngularJS无法在响应数据中检测到JSON。可能是响应中的Content-Type
标头不是application/json
?
你可以尝试用responseType: 'json'
替换$http
配置中的dataType: 'json'
,告诉AngularJS预测JSON响应。
要在警报中显示,使用json将其转换为json字符串。stringify函数。
相关文章:
- React ajax数据集成
- 使用jQuery发布的AJAX数据包含引号
- 如何将Ajax数据值分配给PHP变量
- 使用外部ajax数据PHP绘制图表
- 如何打印AJAX数据
- AJAX数据包含一个或多个单词.
- 将Ajax数据发布到PHP REST服务
- AJAX 数据响应 - 如何解析 html
- 将 Ajax 数据分配给全局变量时出现问题
- 按钮在第一次成功的 ajax 数据加载后不起作用
- Javascript / JQuery循环访问已发布的ajax数据字符串以为其分配新值
- 发送的 Ajax 数据不起作用
- Jquery 工具提示未随 AJAX 数据加载一起显示
- Ajax获取数据以获取另一个Ajax数据
- 如何安全地依赖现有的Ajax数据
- 如何将jquery ajax数据提取为html
- 自定义AJAX数据类型
- 如何将ajax数据发送到rails 3.jQuery正在转义字符串
- jQuery AJAX数据参数
- Laravel 4:通过控制器操作ajax数据