当我做的时候

console.log(JSON.parse(JSON.stringify(e)).data);


我有

{"deviceId":"1234","instanceId":"drogon","operationalEvent":"Shutdown","subEventReason":"Finished","operationalState":"in shutdown","createdAt":"2019-06-07 15:22:17","initiator":"system"}


当我做的时候

console.log(JSON.parse(JSON.stringify(e)).data.deviceId);


我有

app.js:10254 undefined


我做错什么了 ?



更新-更多信息

console.log(typeof JSON.parse(JSON.stringify(e))) //object




console.log(typeof JSON.parse(JSON.stringify(e)).data) //string

最佳答案

JSON.parse(JSON.stringify(e))毫无意义,它与原始对象e相同。因为您说e.data是一个字符串,所以您需要解析以下内容:

let data = JSON.parse(e.data);
console.log(data.deviceId);

07-24 09:38
查看更多