简体   繁体   中英

displaying [object object ] instead of data in the variable: ionic

This is my code

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);

In the emulators alert box, it's showing output as

[object object]

How can I resolve this issue?

As your userData might be an JSON parsed object, it shows [object object] .

Try using alert(JSON.stringify(userData)) and I guess it should solve your problem.

Also if you just want to verify the object data then you can use simply use console.log(userData) .

在显示警报时,您需要使用JSON.stringify,

 alert(JSON.stringify(userData));

use "console.log(userData);" instead of "alert(userData);"

  • alert() is blocking & cannot be easily suppressed in a non-debug environment
  • console typically formats your objects nicely and allows to traverse them

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM