我有一个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.receivedon
和obj.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 };