Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS在我的JSON中遇到麻烦_Json_Angularjs - Fatal编程技术网

AngularJS在我的JSON中遇到麻烦

AngularJS在我的JSON中遇到麻烦,json,angularjs,Json,Angularjs,我从我的网站获得了一个JSON对象: { "ID":"102”, "role":{“subscriber”:true}, "first_name”:”Test 3”, "last_name”:”Test 4”, "custom_fields":{ “job_title”:”testing”}, } AngularJS来管理动态内容,但似乎不起作用: var app = angular.module('myApp', []); function PeopleCtrl($scope,

我从我的网站获得了一个JSON对象:

{ "ID":"102”,
 "role":{“subscriber”:true},
 "first_name”:”Test 3”,
 "last_name”:”Test 4”,
 "custom_fields":{ “job_title”:”testing”},
}
AngularJS来管理动态内容,但似乎不起作用:

var app = angular.module('myApp', []);

 function PeopleCtrl($scope, $http) {

$scope.people = [];

$scope.loadPeople = function () {
    var httpRequest = $http({
        method: 'POST',
        url: '/echo/json/',
        data: mockDataForThisTest

    }).success(function (data, status) {
        $scope.people = data;
    });

};
}
这是一本书


有人能帮我显示数据吗?

您的JSON有很多问题,我已经解决了

里面有不同类型的引号。我已将它们替换为

现在看起来是这样的:

[{         
  "ID": "100",
  "role": {            
    "subscriber": true         
  },
  "first_name": "Test",
  "last_name": "Test2",
  "custom_fields": {            
    "job_title": "subscriber"         
  },
}, {   
  "ID": "102",
  "role": {            
    "subscriber": true         
  },
  "first_name": "Test 3",
  "last_name": "Test 4",
  "custom_fields": {            
    "job_title": "testing"         
  },        
}]
此外,您没有在视图中正确引用模型字段


以下是更新后的工作提琴:

@qqruza要使回调在中正常工作,请将url更改为:

http://test.eventident.com/api/last_posts/siteid=&callpage=1&perpage=10&callback=JSON_CALLBACK

请注意最后的
JSON\u回调
。由于您没有从repeat指令中返回的数据中选择正确的绑定,因此应用程序的其余部分仍然无法工作。请尝试
console.log(data)
在success函数中单击返回的对象并找到正确的路径。

您在最后一个属性的末尾有一个逗号,这通常会出错,下面的JSON应该可以工作:

{ "ID":"102”,
 "role":{“subscriber”:true},
 "first_name”:”Test 3”,
 "last_name”:”Test 4”,
 "custom_fields":{ “job_title”:”testing”}
}

控制台中出现错误Angular的哪个版本?控制台错误表明问题不在于Angular管理内容,而在于Angular初始化。我对JSFIDLE了解不够,无法提供更多帮助。请查看我对下面答案的评论…我非常感谢您的帮助@chrisI已将您的JSFIDLE更新为有效的版本:。此版本检索从结果数组中删除作者,并将每个作者推入
$scope.people
。然后,在“作者”字段中定义的任何内容都将显示在您的视图中。我还添加了一个函数,在将新作者推入数组之前检查重复项(使用作者ID)。没问题。很高兴能提供帮助。