2012-03-07 66 views
1

我使用的console.log(data.result)發現對象層次,這裏的輸出:的Javascript:訪問對象

[
對象
delete_type: 「DELETE」
delete_url:「http://doubleyourlikes.com/lab/time/jq-file-upload/server/php/?file=splash%20%2816%29.png」
name:「splash(16).png 「
size:17369
thumbnail_url:」http://doubleyourlikes.com/lab/time/jq-file- upload/server/php/thumbnails/splash%20%2816%29.png「
type:」image/png「
url:」http://doubleyourlikes.com/lab/time/jq-file-upload/服務器/ PHP /文件/飛濺%20%2816%29.png」
:對象

如何像我這樣的小白訪問該對象...?謝謝!我想要的名字:)

更新
的console.log(data.result)
警報(data.result.name);

警報返回null!

+2

data.result.name – j08691 2012-03-07 01:37:44

回答

0

這很難說,因爲開[沒有關閉,但我相信它意味着對象數組中包含的,所以你訪問它想:

data.result[0].name 
+1

有沒有更簡單的方法來找出該對象是在一個數組?你完美的搖滾! http://screencast.com/t/omwlsuyzw – 2012-03-07 02:07:12

+0

Object.prototype.toString.call(data.result)==='[object Array]' – mVChr 2012-03-07 17:30:29

+0

感謝您的所有幫助!所以你知道它可能是陣列的一部分的唯一方法是因爲我決定粘貼在[?太好了! – 2012-03-07 23:22:40

0

例如,如果您想要訪問delete_type,只需要data.result.delete_typedata.result['delete_type']

+0

好吧,那用這個代碼: 的console.log(data.result) 警報(data.result.name); 警報回來undefined? – 2012-03-07 02:02:45