将字符串对象转换为JSON对象

时间:2020-03-06 04:24:20

标签: arrays node.js json

我正在尝试从字符串对象中获取数据,因此我尝试使用JSON.parse将其转换为json,但是它抛出了错误。

Cannot read property '0' of undefined

这是我的代码。我想从该对象管理日志日期。

var mail = "{ date: [ 'Thu, 5 Mar 2020 17:02:36 +0530' ],'message-id':[ 
 '<C6NzJWkr06VJtksw@mail.gmail.com>' ],subject: [ 'Fwd: one' ],from: [ 'voltus wave <qwerty4@gmail.com>' ],to: [ 'low@gmail.com' ] }";

var jsonmail = JSON.parse(mail);
console.log(jsonmail.date[0])

0 个答案:

没有答案