遍历 Angularjs 中的 JSON 字符串
Iterating through a JSON string in Angularjs
我正在托管一个公开 REST API 的网络服务器。以下是我从服务器获得的 JSON 响应。
[
{
"score": 4,
"sense": "be the winner in a contest or competition; be victorious; \"He won the Gold Medal in skating\"; \"Our home team won\"; \"Win the game\""
},
{
"score": 2,
"sense": "win something through one's efforts; \"I acquired a passing knowledge of Chinese\"; \"Gain an understanding of international finance\""
},
{
"score": 0,
"sense": "obtain advantages, such as points, etc.; \"The home team was gaining ground\"; \"After defeating the Knicks, the Blazers pulled ahead of the Lakers in the battle for the number-one playoff berth in the Western Conference\""
},
{
"score": 4,
"sense": "attain success or reach a desired goal; \"The enterprise succeeded\"; \"We succeeded in getting tickets to the show\"; \"she struggled to overcome her handicap and won\""
}
]
我想在列表中显示它。我正在按以下方式使用 material 设计:
<md-list data-ng-repeat="item in sensesscores track by $index">
<md-item-content>
<div class="md-tile-content">
{{item.sense}}
</div>
<div class="md-tile-left">
{{item.score}}
</div>
</md-item-content>
</md-list>
在我的控制器中,我有以下内容:
$http.get('http://localhost:8080/nlp-wsd-demo/wsd/disambiguate').
success(function(data) {
$scope.sensesscores = data;
console.log(data);
});
我确保我能够获取 'sensesscores' 中的数据并将其打印在屏幕上。但是,我无法解析并将其显示在列表中。提前致谢。
编辑
我更改了代码以更正语法并将 ng-repeat 移到层次结构中,但它仍然不起作用。但是,我在另一个 JSON 文件上尝试过,效果很好。
[{
"sense": "sensaS,NF,ASNGD.,AD., BVAS.,GMDN,FG e1",
"score" : 5
},
{
"sense": "sen ASG SFG S H D GD FJDF JDF J GFJ FDFGse2",
"score" : 13
}
,
{
"sense": "sen ASG SFG S H D GD FJDF JDF J GFJ FDFGse2",
"score" : 1
},
{
"sense": "sen ASG SFG S H D GD FJDF JDF J GFJ FDFGse2",
"score" : 0
},
{
"sense": "sen ASG SFG S H D GD FJDF JDF J GFJ FDFGse2",
"score" : 3
},
{
"sense": "sen ASG SFG S H D GD FJDF JDF J GFJ FDFGse2",
"score" : 2
},
{
"sense": "sen ASG SFG S H D GD FJDF JDF J GFJ FDFGse2",
"score" : 1
}
]
我不明白 JSON 响应有什么问题。
您的 HTML 有很多错别字,以下格式正确:
<md-list>
<md-item data-ng-repeat="item in sensesscores track by $index">
<md-item-content>
<div class="md-tile-content">
{{item.sense}}
</div>
<div class="md-tile-left">
{{item.score}}
</div>
</md-item-content> // this tag was not closed, but rather a new opener
</md-item>
</md-list> // this tag was not closed properly, missing ">"
更改它,您的数据将按您的预期显示。
我想出了解决办法。内容需要转换为 json 对象,我使用 jquery - $.parseJSON(data)
我正在托管一个公开 REST API 的网络服务器。以下是我从服务器获得的 JSON 响应。
[
{
"score": 4,
"sense": "be the winner in a contest or competition; be victorious; \"He won the Gold Medal in skating\"; \"Our home team won\"; \"Win the game\""
},
{
"score": 2,
"sense": "win something through one's efforts; \"I acquired a passing knowledge of Chinese\"; \"Gain an understanding of international finance\""
},
{
"score": 0,
"sense": "obtain advantages, such as points, etc.; \"The home team was gaining ground\"; \"After defeating the Knicks, the Blazers pulled ahead of the Lakers in the battle for the number-one playoff berth in the Western Conference\""
},
{
"score": 4,
"sense": "attain success or reach a desired goal; \"The enterprise succeeded\"; \"We succeeded in getting tickets to the show\"; \"she struggled to overcome her handicap and won\""
}
]
我想在列表中显示它。我正在按以下方式使用 material 设计:
<md-list data-ng-repeat="item in sensesscores track by $index">
<md-item-content>
<div class="md-tile-content">
{{item.sense}}
</div>
<div class="md-tile-left">
{{item.score}}
</div>
</md-item-content>
</md-list>
在我的控制器中,我有以下内容:
$http.get('http://localhost:8080/nlp-wsd-demo/wsd/disambiguate').
success(function(data) {
$scope.sensesscores = data;
console.log(data);
});
我确保我能够获取 'sensesscores' 中的数据并将其打印在屏幕上。但是,我无法解析并将其显示在列表中。提前致谢。
编辑
我更改了代码以更正语法并将 ng-repeat 移到层次结构中,但它仍然不起作用。但是,我在另一个 JSON 文件上尝试过,效果很好。
[{
"sense": "sensaS,NF,ASNGD.,AD., BVAS.,GMDN,FG e1",
"score" : 5
},
{
"sense": "sen ASG SFG S H D GD FJDF JDF J GFJ FDFGse2",
"score" : 13
}
,
{
"sense": "sen ASG SFG S H D GD FJDF JDF J GFJ FDFGse2",
"score" : 1
},
{
"sense": "sen ASG SFG S H D GD FJDF JDF J GFJ FDFGse2",
"score" : 0
},
{
"sense": "sen ASG SFG S H D GD FJDF JDF J GFJ FDFGse2",
"score" : 3
},
{
"sense": "sen ASG SFG S H D GD FJDF JDF J GFJ FDFGse2",
"score" : 2
},
{
"sense": "sen ASG SFG S H D GD FJDF JDF J GFJ FDFGse2",
"score" : 1
}
]
我不明白 JSON 响应有什么问题。
您的 HTML 有很多错别字,以下格式正确:
<md-list>
<md-item data-ng-repeat="item in sensesscores track by $index">
<md-item-content>
<div class="md-tile-content">
{{item.sense}}
</div>
<div class="md-tile-left">
{{item.score}}
</div>
</md-item-content> // this tag was not closed, but rather a new opener
</md-item>
</md-list> // this tag was not closed properly, missing ">"
更改它,您的数据将按您的预期显示。
我想出了解决办法。内容需要转换为 json 对象,我使用 jquery - $.parseJSON(data)