javascript - Unable to fetch object value -


i struggling figure out why getting "undefined" when trying fetch object value.

my object, called "message" looks this:

{"username":"123","password":"123"} 

when try fetch either username or password following:

message.username message['username'] 

i "undefined".

what's correct way fetch values?

code gets message , displays it:

window.messagebus.onmessage = function(event) {     displaytext(event.data); // spits out {"username":"123","password":"123"} }  function displaytext(message) {     document.getelementbyid("message").innerhtml = message.username + ' - ' + message.password; }; 

edit - object being received chromecasts "window.messagebus.onmessage" function. assumed because sent message proper object, should have bene spat proper object, seems might not case!

well, no idea why wasn't working code posted, means should have.

anyway, fixed using "json.parse()" on "message" variable passed "displaytext()"

i able use "message.username" value.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -