undefined:1未定义^ SyntaxError:JSON中位置0处的意外令牌u

这是我的代码,记录了数据,但随后或发生错误时中途发生。

错误消息是

undefined:1
undefined
^

SyntaxError: Unexpected token u in JSON at position 0
function script() {
  request('https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty', function(error, res, body){
    for(let i = 0; i <= body.length; i++) {
      let obj = JSON.parse(body)
      request(`https://hacker-news.firebaseio.com/v0/item/${obj[i]}.json?print=pretty`, function(error, res, body){
        let myData = JSON.parse(body);
        if(myData && myData.title && myData.score && myData.id) {
          console.log('TITLE: ', myData.title)
          console.log('UPVOTES: ', myData.score)
          console.log(`https://news.ycombinator.com/item?id=${myData.id}`)
        }
      })
    }
  })
}
评论