Unexpected token u in JSON at position solution

Generally, the problem of Unexpected token u in JSON at position 0 occurs because JSON.parse parses undefined. At this time, we find the JSON parsing code, find out why undefined appears and add a judgment statement.

 onLoad(query) {
    console.log(query)
    if(query.orderRow){
           this.setData({
      orderRowList:JSON.parse(query.orderRow),
    })
    }else{
    this.getGoodsInfo(query.goodsId)
       this.setData({
         ["orderRowList.goodsId"]:query.goodsId,
         ["orderRowList.pid"]:query.pid
       })
    }
  
    
  },

This problem occurred in my code because different pages entered the same page with different parameters, which resulted in the parsing of undefined. So an if statement is added outside to distinguish between the two pages passing parameters.

Guess you like

Origin blog.csdn.net/weixin_51110842/article/details/117284373