从angular2中的api接收json数组

时间:2017-02-02 13:43:13

标签: json api angular

我正在尝试从api接收一个json数组并在页面上显示它,我很确定我的服务有问题,我只是不知道是什么。

   getAuctions(): Promise<Auction[]> {
        return this.http.get(this.auctionsUrl)
            .toPromise()
            .then(response => response.json().array as Auction[])
            .catch(this.handleError);
    }

这是一个回复示例

[
  {
    "id": 1,
    "name": "Antik stol",
    "description": "En fin antik stol från 1800-talet",
    "startTime": "2016-12-13T10:00:00",
    "endTime": "2017-02-23T10:00:00",
    "imageUrl": "https://thumbs.dreamstime.com/z/antik-stol-som-stoppas-i-sammet-32935346.jpg",
    "categoryId": 1,
    "supplierId": 2,
    "buyNowPrice": 8000,
    "sold": true
  },
  {
    "id": 2,
    "name": "Antikt bord",
    "description": "En fint antikt bord",
    "startTime": "2016-12-10T10:00:00",
    "endTime": "2017-03-29T10:00:00",
    "imageUrl": "http://precisensan.com/antikforum/attachment.php?attachmentid=78277&stc=1&d=1292057973",
    "categoryId": 1,
    "supplierId": 1,
    "buyNowPrice": 18000,
    "sold": false
  }
]

1 个答案:

答案 0 :(得分:-2)

AuctionService:

Dim sent
Dim i
Dim j
Dim k
sent = "Its a good day but every day is a good day"
words = Array(Split(sent))
For i = LBound(words) To UBound(words)-1
  For j = LBound(words)+1 To UBound(words)
    k = StrComp(words(i), words(j))
    If k=0 Then
      MsgBox ("Match")
    Else
      MsgBox ("No Match")
    End If
  Next
Next

AuctionComponent:

getAuctions() : Observable<Auction[]> {
        return this.http.get(this.auctionsUrl)
            .map((response: Response) => response.json())
            .catch(this.handleError)
    }