2016-01-06 107 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>