这是我的代码片段:我知道我从我的webservice获得了一个结果,因为它返回了200 ok。 但我无法循环以拉出数据元素。
this.cityService.searchByRegion(formData)
.subscribe((resultsReturned) => {
console.log("ResultsReturned :" + resultsReturned);
resultsReturned.forEach((city) => {
var newSearchResult = new SearchResult(city);
this.results.push(newSearchResult);
});
这是返回的JSON:
[ {
"region_id" : "8",
"time" : "2015-01-16T08:31:40",
"bus_count" : "200",
"speed" : "15.68",
"number_of_reads" : "3412"
}
, {
"region_id" : "8",
"time" : "2015-01-15T08:31:39",
"bus_count" : "200",
"speed" : "15.68",
"number_of_reads" : "3535"
}
, {
"region_id" : "8",
"time" : "2015-01-14T08:40:47",
"bus_count" : "200",
"speed" : "14.32",
"number_of_reads" : "3463"
}]
如何使用forEach返回解析出的JSON数据? 我尝试了returnResults.json ...但是刚刚返回了一个对象:object
我对Angular2很新,所以任何帮助都会受到赞赏。