I have a function that goes something like this
data = JSON.parse(data)
Initially, data
is a string formatted as follows:
"{\"content\":\"Hello there\",\"uid\":\"OoIEfsgabT89EJw\",\"createdAt\":1451586225268,\"user\":{\"avatar\":\"https://avatars.com/123?v=3\",\"login\":\"login\",\"name\":\"Username\",\"uid\":123}}"
After transforming the data, it looks like this:
{"content":"Hello there","uid":"OoIEfsgabT89EJw","createdAt":1451586225268,"user":{"avatar":"https://avatars.com/126?v=3","login":"login","name":"Username","uid":123}}
But when attempting to access data.uid
, it returns undefined
. What could be causing this issue?
Upon closer inspection of the code:
addItem: function(data) {
data = JSON.parse(data)
console.log("Adding: "+data)
console.log("Adding: "+data.uid)
},
An additional note indicates that the JSON was double encoded. Although parsing the data twice resolved the issue temporarily, it is not the correct solution. How else can this problem be addressed?