2011-08-23 94 views
3

我在查詢LinkedIn JS API以返回人員列表。該列表作爲JSON對象返回。這裏是回調函數:訪問JSON對象的問題

.result(function (result) { 
     profile = result.values[0]; 
     // Do something with the first linkedin profile in the list... 
    }); 

對象「結果」返回類似如下:

{"values":[{"id":"123456","firstName":"Person","lastName":"One"}, {"id":"123456","firstName":"Person","lastName":"Two"}, {"id":"123456","firstName":"Person","lastName":"Three"}],"_total":3} 

我見過的所有文件使用此語法從結果得到的第n項:

var profile = result.values[n]; 

這適用於大多數瀏覽器,但在IE中它拋出以下錯誤:

Microsoft JScript runtime error: Object doesn't support this property or method 

有沒有人有任何想法解決這個問題?

在此先感謝。

+0

我在IE9測試,一切順利。 – xdazz

+4

你正在使用'profile = ...'還是'var profile = ...'? – Jochem

+0

哪個版本的ie? – naveen

回答

0

由於「價值」鍵是一個字符串,下面可能工作(對不起,沒有IE瀏覽器進行測試):

var profile = result['values'][n];