如何用AnjularJS解析JSON?

时间:2016-07-24 19:23:51

标签: angularjs json

我正在尝试使用像这样的AngularJS来解析JSON文件,

<!DOCTYPE html>
<html lang="en" ng-app="tutorialApp">
<head>
    <meta charset="UTF-8">
    <title>App</title>

    <script src="lib/angular.min.js"></script>
    <script src="js/app.js"></script>

</head>

<body ng-controller="ListController">

<ul>
    <li ng-repeat="item in artists">
        {{item.name}}
    </li>
</ul>

</body>
</html>

由于某种原因,<li>标记不显示JSON数据。

这是我的 app.js 文件,

var app = angular.module("tutorialApp", []);

app.controller('ListController', ['$scope', '$http', function($scope, $http) {
    $http.get('js/data.json').success(function (data) {
        $scope.artists = data;
    });
}]);

这是我的 data.json 文件,

{ "speakers" : [
  { 
    "name":"Mr Bellingham",
    "shortname":"Barot_Bellingham",
    "reknown":"Royal Academy of Painting and Sculpture",
    "bio":"Barot has just finished his final year at The Royal Academy of Painting and Sculpture, where he excelled in glass etching paintings and portraiture. Hailed as one of the most diverse artists of his generation, Barot is equally as skilled with watercolors as he is with oils, and is just as well-balanced in different subject areas. Barot's collection entitled \"The Un-Collection\" will adorn the walls of Gilbert Hall, depicting his range of skills and sensibilities - all of them, uniquely Barot, yet undeniably different"
  },
  {
    "name":"Jonathan G. Ferrar II",
    "shortname":"Jonathan_Ferrar",
    "reknown":"Artist to Watch in 2012",
    "bio":"The Artist to Watch in 2012 by the London Review, Johnathan has already sold one of the highest priced-commissions paid to an art student, ever on record. The piece, entitled Gratitude Resort, a work in oil and mixed media, was sold for $750,000 and Jonathan donated all the proceeds to Art for Peace, an organization that provides college art scholarships for creative children in developing nations"
  },
  {
    "name":"Hillary Hewitt Goldwynn-Post",
    "shortname":"Hillary_Goldwynn",
    "reknown":"New York University",
    "bio":"Hillary is a sophomore art sculpture student at New York University, and has already won all the major international prizes for new sculptors, including the Divinity Circle, the International Sculptor's Medal, and the Academy of Paris Award. Hillary's CAC exhibit features 25 abstract watercolor paintings that contain only water images including waves, deep sea, and river."
  }
]}

如何仅显示JSON文件中的名称对象?我错过了什么?

0 个答案:

没有答案