微信小程序 从java后台获取encode的数据并decode的问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m940034240/article/details/82835643

如果java后台通过URLEncoder.encode(data,"UTF-8")方法将data字符串进行了编码后再返回给前台,

小程序获取到这个字符串的时候需要调用decodeURIComponent进行解码

wx.request({
  url: url,//后台接口url
  data: {},//需要传递的参数,json格式
  success: function(res) {
    console.log('success:')
    var a = decodeURIComponent(res.data)
    var json = JSON.parse(a);
    console.log(json);    
  },
})

猜你喜欢

转载自blog.csdn.net/m940034240/article/details/82835643