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
response.farewell.msg? without usingJSON.stringifyorJSON.parse?tmpa variable ?response.farewellinitially?"at\"" + tmp + "\"?"REPLY: Object {msg: "not_inserted"}"on my side if I useresponse = { farewell: { "msg": "not_inserted" } }