Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

你好,小程序获取的用户授权信息,返回的是字符串类型,不是对象,应该转换成对象 #1

Open
output opened this issue Oct 13, 2020 · 0 comments

Comments

@output
Copy link

output commented Oct 13, 2020

wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId

          var userinfo_get = res.rawData;

          if(res.rawData.constructor != Object){

console.log("获取的用户信息不是对象,转换");
userinfo_get = JSON.parse(res.rawData);
}

          app.globalData.userInfo = userinfo_get;
          that.setData({
            userInfo: userinfo_get
          });
        
          // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
          // 所以此处加入 callback 以防止这种情况
          if (that.userInfoReadyCallback) {
            that.userInfoReadyCallback(res)
          }
        }
      })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant