[英]Javascript, console.log prints prints object, but property is undefined
[英]JSON.stringify prints object to console, object.property prints undefined
我的角度應用程序給我一個問題
console.log(JSON.stringify($rootScope.user));
正在按預期方式打印出用戶對象,但是...
當我嘗試
console.log($rootScope.user.objectId)
要么
var id = $rootScope.user.objectId;
console.log(id);
我變得不確定。 那是怎么回事? userId絕對是JSON.stringify
打印出來的屬性JSON.stringify
,所以...我很困惑。
{"username":"thinmint","email":"thinmint@thinmint.com","objectId":"FmjGa7POFH",
"createdAt":"2015-05-28T18:39:08.362Z","updatedAt":"2015-05-28T18:39:08.362Z"}
那就是$rootScope.user
的示例值。
var json = {
"username": "thinmint", "email": "thinmint@thinmint.com", "objectId": "FmjGa7POFH",
"createdAt": "2015-05-28T18:39:08.362Z", "updatedAt": "2015-05-28T18:39:08.362Z"
};
var json1 = JSON.parse(JSON.stringify(json));
alert(json1.username);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.