我正在托管一个公开REST API的Web服务器。以下是我从服务器获得的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\""
}
]
我想在列表中显示这个。我正在使用材料设计,方法如下:
<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);
});
我确保我能够将感知数据传输到感应器中。并将其打印在屏幕上。但是,我无法进行解析并将其显示在列表中。提前谢谢。
修改
我更改了代码以更正语法并将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响应有什么问题。
答案 0 :(得分:0)
您的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 ">"
更改它,您的数据将按预期显示。
答案 1 :(得分:0)
我找到了解决方案。需要将内容转换为json对象,我使用jquery - $ .parseJSON(data)