Search code examples
javascriptandroidjsoncordovastringify

Object object can't be converted to string


I'm trying to access the mobile contacts using phone gap on Android. I access the contacts & show them in a drop down box, then the user should select the desired contact and this contact is supposed to be shown at a text box after that.

Now when I click on one of the contacts in the contact list, the text box's value changes to [object object].

I tried:

    JSON.stringify(data.value);

but it just changes [object object] to "[object object]".

I tried:

    data.value.tostring(); 

&

    data.value.formatted;

but then the output is undefined.

That's the jS line I change the text box content with:

       document.getElementById ("friendName").value = "/*Stringified data is written here*/;

So do you know how can I change the object object, to a normal readable string ?


Solution

  • If your "data" object is of type Contact then you should be using data.displayName or data.name.formatted if you want the contacts name.