簡體   English   中英

JSON.stringify將對象打印到控制台,object.property打印未定義

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM