2016-01-06 191 views
0

我有通过JSON对象列表循环的功能。它的实际工作,但它给了我这个错误:“遗漏的类型错误:无法未定义读取属性‘值’”指着这行:传递参数正确

var resValues = result.values; 

我的代码是:

function onLinkedInLoad() { 
    IN.Event.on(IN, "auth", onLinkedInAuth); 
} 

function onLinkedInAuth() { 
    var cpnyID = 2414183; //LinkedIn's testDevCo 
    IN.API.Raw("/companies/" + cpnyID + "/updates?event-type=status-update&start=0&count=10&format=json") 
     .result(displayUpdates); 
} 

function displayUpdates(result) { 
    var resValues = result.values; 
    for (var i in resValues) { 
     var share = resValues[i].updateContent.companyStatusUpdate.share; 
     console.log(share); 
    } 
} 

做什么,我需要更改以修复此错误?

的JSON看起来是这样的:

{ 
    "values": [{ 
     "updateContent": { 
      "companyStatusUpdate": { 
       "share": { 
        "content": { 
         "description": "Test description", 
         "eyebrowUrl": "http://linkd.in/…", 
         "shortenedUrl": "http://linkd.in/…", 
         "submittedImageUrl": "http://m.c.lnkd.licdn.com/…", 
         "submittedUrl": "http://linkd.in/…", 
         "thumbnailUrl": "https://media.licdn.com/…", 
         "title": "Best Advice: Take Jobs Others Don't Want" 
        } 
       } 
      } 
     } 
    }] 
} 

非常感谢提前。

+0

告诉我们在哪儿,你使用'代码displayUpdates',因为它看起来像你给它一个错误的参数。 – leroydev

+0

编辑你的问题,并在那里添加代码,因为它没有格式在这里,它不属于评论。 – leroydev

+0

您的代码工作正常在'node' ...... –

回答

0

事实证明,这种错误的出现是因为我是上市displayupdates进一步向上在输入API密钥头部分:我删除它,所以我只是有:

<script type="text/javascript" src="https://platform.linkedin.com/in.js"> 
    api_key: xxxxxxxxxxxxxxxx 
    **onLoad: onLinkedInLoad, onLinkedInAuth** 
    authorize: true 
</script>