我有一个JSON对象,如下所示:

{"_id":"594fe31b3e158c0e70c9bb3e","deviceid":"342","alldata":"{\"deviceid\":\"342\",\"voltage\":\"14\",\"current\":\"9\",\"power\":\"92\",\"status\":\"1\"}","receivedon":"2017/06/25 21:51:47","__v":0}


问题是,当我尝试输出obj.alldata.voltage时,它只是空白。这使我认为obj.alldata是字符串而不是JSON对象。

当我打印obj.alldata时,它给出如下输出:

{"deviceid":"342","voltage":"14","current":"9","power":"92","status":"1"}


如何正确使用obj.receivedonobj.alldata.voltage

最佳答案

删除alldata值的引号,因此不会将其视为字符串。

{ "_id": "594fe31b3e158c0e70c9bb3e", "deviceid": "342", "alldata": { "deviceid":"342","voltage":"14","current":"9","power":"92","status":"1"}, "receivedon": "2017/ 06 / 25 21: 51:47", "__v": 0 };

10-04 10:11