2012-05-30 36 views
4

我正在使用多查詢來獲取朋友簽入。我有查詢按預期返回數據,但我想要做的是創建一個DataTable,其中包含來自每個查詢的元素。我只有3個結果,但數據中至少有一百個。我不確定我在做什麼錯,除了我知道我的循環是不正確的。具有諷刺意味的是,3是查詢的數量。我確定這是我的foreach,但我不確定我應該循環播放。請幫忙。Facebook C#使用多查詢結果

dynamic resultCheckins = fb.Get("fql", 
    new 
    { 
     q = new 
     { 
      friends_checkins = "SELECT author_uid, coords, timestamp, page_id, message FROM checkin WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me())", 
      users = "SELECT uid, name, pic_small from user where uid IN (SELECT author_uid FROM #friends_checkins)", 
      resultCheckins = "SELECT page_id, name, description from place where page_id IN (SELECT page_id FROM #friends_checkins)", 
     } 
    }); 

JObject resultCheckinsJson = JObject.Parse(resultCheckins.ToString()); 
DataTable CheckIn = new DataTable(); 
CheckIn.Columns.Add(new DataColumn("Friend", typeof(string))); 
CheckIn.Columns.Add(new DataColumn("Picture", typeof(string))); 
CheckIn.Columns.Add(new DataColumn("Link", typeof(string))); 
CheckIn.Columns.Add(new DataColumn("Place", typeof(string))); 
CheckIn.Columns.Add(new DataColumn("Coords", typeof(string))); 
CheckIn.Columns.Add(new DataColumn("When", typeof(string))); 
CheckIn.Columns.Add(new DataColumn("Message", typeof(string))); 

int thiscounter = 0; 
foreach (var row in resultCheckinsJson["data"].Children()) 
{ 
    string placename = resultCheckins.data[1].fql_result_set[thiscounter].name.ToString().Replace("\"", ""); 
    string NavigateURL = "http://facebook.com/" + resultCheckins.data[1].fql_result_set[thiscounter].page_id.ToString().Replace("\"", ""); 

    DataRow CheckInRow = CheckIn.NewRow(); 
    CheckInRow["Friend"] = resultCheckins.data[2].fql_result_set[thiscounter].name; 
    CheckInRow["Picture"] = resultCheckins.data[2].fql_result_set[thiscounter].pic_small; 
    CheckInRow["Link"] = ResolveUrl(NavigateURL); 
    CheckInRow["Place"] = resultCheckins.data[1].fql_result_set[thiscounter].name.ToString().Replace("\"", ""); 
    CheckInRow["Coords"] = resultCheckins.data[0].fql_result_set[thiscounter].coords.ToString().Replace("\"", ""); 
    DateTime dtDateTime = dtDateTime.AddSeconds(resultCheckins.data[0].fql_result_set[thiscounter].timestamp).ToLocalTime(); 
    CheckInRow["When"] = dtDateTime.ToString(); 
    CheckInRow["Message"] = resultCheckins.data[0].fql_result_set[thiscounter].message.ToString(); 
    CheckIn.Rows.Add(CheckInRow); 
    thiscounter++; 
} 
+0

我從來沒有與Facebook AP合作過我,但在接下來的問題中,那個人用另一個邏輯取得了結果(我也幫他回答了我的答案)。請檢查它:http://stackoverflow.com/questions/11623714/convert-fql-results-to-custom-class/11624318#11624318 –

+0

你可以發佈JSon你回來了(與個人信息混淆,或課程:-))。將有助於回答這個問題... –

回答

0

嘗試修改此行:

foreach (var row in resultCheckinsJson["data"].Children()) 

要:

的foreach(動態行resultCheckinsJson.data)

然後得到的屬性是這樣的:

row.name