Reputation:
Why jsonObject.msg
is undefined
? even i am getting value as {"msg":"not_inserted"}
from response.farewell
.
( FYI: where response.farewell is Google chrome apps generated JSON value sendMessage("{\"msg\" : \"" + tmp + "\"}");
)
//var reply ='{"msg":"not_inserted"}';
//var jsonstring = JSON.parse(reply);
//console.log('>>> ' , jsonstring.msg); // it WORKS!
try {
console.log("REPLY: ", response.farewell);
// it FAILS!!
var jsonString = JSON.stringify(response.farewell);
var jsonObject = JSON.parse(jsonString);
console.log('>>> ' , jsonObject.msg);
} catch(eio) {
console.log(eio);
}
Output:
REPLY: {"msg":"not_inserted"}
>>> undefined
Expected output:
>>> not_inserted
Upvotes: 0
Views: 1736
Reputation: 1
Try using single quotes to wrap string passed to sendMessage
, removing extra double quotes
sendMessage('{\"msg\" : \"' + tmp + '\"}')
Upvotes: 1