显示 [object object ] 而不是变量中的数据:ionic

nav*_*vya 0 javascript typescript ionic3 angular

这是我的代码

this.facebook.login(['email', 'public_profile']).then((response: FacebookLoginResponse) => {
      this.facebook.api('me?fields=id,name,email,first_name,picture.width(720).height(720).as(picture_large)', [])
      .then((profile: any) => {
        let userData = {
          email: profile['email'],
          first_name: profile['first_name'],
          picture: profile['picture_large']['data']['url'],
          username: profile['name'],
          id: profile['id']
        }
        alert(userData);
Run Code Online (Sandbox Code Playgroud)

在模拟器警报框中,它将输出显示为

[对象对象]

我该如何解决这个问题?

Sun*_*ekh 5

由于您userData可能是 JSON 解析的对象,因此它显示[object object].

尝试使用alert(JSON.stringify(userData)),我想它应该可以解决您的问题。

此外,如果您只想验证对象数据,那么您可以简单地使用 console.log(userData).