2011-08-23 91 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];