2016-11-28 30 views
-1

我有一個我正在使用的JSON對象。這是HTTP GET請求的結果。爲什麼省略了一些JSON屬性?

預期結果如下:

{ 
    "name": { 
    "type": "string" 
    }, 
    "authors": { 
    "collection": "users", 
    "via": "IDPid" 
    }, 
    "id": { 
    "type": "integer", 
    "autoIncrement": true, 
    "primaryKey": true, 
    "unique": true 
    } 
} 

實際結果如下(省略了該authors屬性):

{ 
    "name": { 
    "type": "string" 
    }, 
    "id": { 
    "type": "integer", 
    "autoIncrement": true, 
    "primaryKey": true, 
    "unique": true 
    } 
} 

爲什麼它拿出作者屬性?

但是,當我在Chrome中進行調試時,儘管authors屬性仍然被忽略,但我能夠執行console.log(response.authors)並且它讀取的很好。

此外,當我轉到Chrome開發工具的網絡選項卡來查看HTTP請求的響應時,它會在響應正文中顯示缺少的屬性。

+2

你能給我們一個工作的例子嗎?或者至少告訴我們你如何查看「**實際**」結果? – Gavin

+1

你在哪裏看到沒有authors屬性的json數據?網絡標籤向你顯示逐字提供給你的數據。這是響應您的GET請求而回來的內容。 –

回答

1

我發現了這個問題。這是因爲console.log不能馬上運行。它會在一段時間後運行。我有其他修改對象的代碼,但是由於某種原因,console.log在代碼之後運行,即使我以前寫過它。

相關問題