Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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
Json 从http请求生成列表_Json_Angularjs_List - Fatal编程技术网

Json 从http请求生成列表

Json 从http请求生成列表,json,angularjs,list,Json,Angularjs,List,我的控制器中有以下代码: @RequestMapping("/allU") public List<Utilisateur> AllU() { return UtilisateurRepo.findAll(); } 结果将是object对象,而不是json列表。 当我直接在浏览器中发出请求(/Allu)时,我会得到json列表。 我想知道如何从http请求中检索此列表,因为您没有使用承诺。用这样的承诺: $http.get("/allU"

我的控制器中有以下代码:

 @RequestMapping("/allU")
    public List<Utilisateur> AllU()
    {
        return UtilisateurRepo.findAll();

    }
结果将是object对象,而不是json列表。 当我直接在浏览器中发出请求(/Allu)时,我会得到json列表。
我想知道如何从http请求中检索此列表,因为您没有使用承诺。用这样的承诺:

$http.get("/allU").then(function(data) {
    $scope.list = data; //data from api
}, function(error) {
    //handle in case api fails
});

我们必须使用承诺,因为ajax调用本质上是异步的,我们需要一个承诺来处理请求完成时返回的数据。

尝试JSON.parse()可能吗?我使用了您的响应,但结果未定义。请帮助我们是否从api接收到任何数据?请尝试在“then”块中执行console.log(数据)以了解这一点。
$http.get("/allU").then(function(data) {
    $scope.list = data; //data from api
}, function(error) {
    //handle in case api fails
});