[英]Problem accessing JSON object
我正在查詢LinkedIn JS API以返回人員列表。 此列表作為JSON對象返回。 這是回調函數:
.result(function (result) {
profile = result.values[0];
// Do something with the first linkedin profile in the list...
});
對象'result'返回如下內容:
{"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
有沒有人有任何想法繞過這個?
提前致謝。
由於'values'鍵是一個字符串,以下可能有效(抱歉,沒有IE測試):
var profile = result['values'][n];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.