按照本教程操作:http://www.w3schools.com/angular/angular_http.asp我可以完美解析 json,但我遇到了问题..我有一个带有 json 的 php,其中里面有一个像这样的 json:
{"item":[
{
"Name" : "Alfreds Futterkiste",
"City" : "Berlin",
"Country" : "Germany"
},
{
"Name" : "Berglunds snabbköp",
"City" : "Luleå",
"Country" : "Sweden"
}]}
正如你所看到的,有一个 JSONObject (item).. 实际上,要解析没有 JSONObject 的 json,我在 Controller 中执行此函数:
$http.get(JSONUrl)
.success(function(response) {
$scope.names = response;
});
然后
<div data-ng-controller="MainController">
<table class="uk-table uk-table-striped uk-table-hover" data-ng-if="!loading && !error">
<thead>
<th>Nome</th>
<th>Ver</th>
<th>Code</th>
</thead>
<tbody>
<tr data-ng-repeat="item in names">
<td>{{item.Name}}</td>
<td>{{item.City}}</td>
<td>{{item.Country}}</td>
</tr>
</tbody>
</table>
</div>
但就我而言,我没有显示任何内容,因为我将该“项目”作为 JSONObject ..有什么解决方案吗?
最佳答案
您的问题是您没有在响应 JSON 对象中使用正确的属性
使用
<tr data-ng-repeat="item in names.item">
而不是
<tr data-ng-repeat="item in names">
或
$scope.names = response.item;
关于javascript - 在angularjs中使用JSONObject读取json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28482840/