【发布时间】:2017-02-09 23:15:18
【问题描述】:
我是 Angular 的新手。我正在尝试获取这样编写的 Json 数据:
id:1,
name: "Friends",
type: "Group",
现在,我知道我不能使用这种数据,除非我添加双引号 - 就像那样(这是它工作的唯一方式):
"id":1,
"name": "Friends",
"type": "Group",
在 Angular 中解析 JSON 的最佳方法是什么?
我尝试过结合 JS ,但没有成功:
app.controller('contacts', function ($scope,$http,$log) {
$http.get('http://localhost/Angular-Http-exercise/db.json')
.then(function(response) {
$scope.myData = function() {
return JSON.stringify(response.data)
};
$log.info(response.data.name);
});
});
【问题讨论】:
-
首先确保源是有效的 json。如果该文件的内容未在 jsonlint.com 上验证...修复它。除此之外,这个问题没有多大意义
-
charlietfl -谢谢
-
AngularJS $http 服务自动解析 JSON 数据。没有必要做任何事情。,