简体   繁体   English

访问JSON对象时出现问题

[英]Problem accessing JSON object

I am querying the LinkedIn JS API to return a list of people. 我正在查询LinkedIn JS API以返回人员列表。 This list is returned as a JSON object. 此列表作为JSON对象返回。 Here is the call back function: 这是回调函数:

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

The object 'result' returns something like the following: 对象'result'返回如下内容:

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

All documentation I have seen uses this syntax to get the nth item from the result: 我见过的所有文档都使用这种语法从结果中获取第n项:

var profile = result.values[n];

This works well in most browsers but in IE it throws the following error: 这适用于大多数浏览器,但在IE中它会引发以下错误:

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

Has anybody got any idea to get around this? 有没有人有任何想法绕过这个?

Thanks in advance. 提前致谢。

由于'values'键是一个字符串,以下可能有效(抱歉,没有IE测试):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM