2012-09-12 48 views
0

我嘗試了students.item [「http://www.myurl.com」] .comments.data.length的選項。但是,該項目[「http://www.myurl.com」]呼叫不起作用。通過Facebook評論迭代JSON對象失敗

如果我從JSON對象中取出URL並使用students.comments.data編寫迭代器,它將起作用。

這是我的代碼,任何幫助高度讚賞。

var students = { 
    "http://www.myurl.com":{ 
     "comments":{ 
       "data" : [{ 
        "id": "123456778", 
        "from": { 
         "name": "XYZ", 
         "id": "1000005" 
         }, 
        "message": "Hey", 
        "can_remove": false, 
        "created_time": "2012-09-03T03:16:01+0000", 
        "like_count": 0, 
        "user_likes": false 
       }] 
      } 
     } 
    } 

var i=0 
var arrayObject = new Array(); 
alert("Parsing 2: "+students.item["http://www.myurl.com"].comments.data.length); 
for(i=0;i<students.item["http://www.myurl.com"].comments.data.length;i++) 
{ 
    alert("Parsing 1: "+i); 
    arrayObject.push(students.item["http://www.myurl.com"].comments.data[i].id); 
    arrayObject.push(students.item["http://www.myurl.com"].comments.data[i].message); 
    arrayObject.push(students.item["http://www.myurl.com"].comments.data[i].created_time); 
} 
+0

.item從哪裏來?這似乎是不必要的 – endyourif

回答

0

students對象沒有item屬性僅http://www.myurl.com。使用students["http://www.myurl.com"]而不是students.item["http://www.myurl.com"]

+0

謝謝穆薩。它確實有用! – user1594304