后台的json数据,无法调用具体数据
发布于 6 年前 作者 jing71 10288 次浏览 来自 问答

//index.js


onLoad: function () {


    var that = this


    wx.request({


      url: ‘http://127.0.0.1:8080/tmall/foreproduct?pid=1’, 



      header: {


        ‘content-type’: ‘application/json’


      },


      success: function (res) {


        console.log(res.data)   //这里成功打印出了数据


        console.log(res.data.product)   //这里打印显示undefined


      },


      fail: function (res) {


        console.log(“fail”)


      }


    }) 

<ignore_js_op style=""> </ignore_js_op>


  },

3 回复

res.data 是一个数组。

应该是 console.log(res.data[0].product) 

wx.request请求写的有问题吧

  1. var that = this

  2.       wx.request({

  3.         url: 'https://www.njbrick.com/ocrserver/getweather?city='+this.data.city1,

  4.         headers: {

  5.           'Content-Type': 'application/json'

  6.         },

  7.         success: function (res) {

  8.           that.setData({

  9.             weather: res.data.data,//第一个data为固定用法,第二个data是json中的data


  10.           })

  11.         }

  12.       })

咫尺开发论坛——小乐    

console.log(res.data[0].product)试试看

回到顶部