4

我正在使用多重查询来让朋友签到。我有查询按预期返回数据,但我想做的是创建一个包含每个查询的元素的 DataTable。我只有 3 个结果,但数据中至少有 100 个。除了我知道我的循环不正确之外,我不确定我做错了什么。具有讽刺意味的是,3 是查询的数量。我确定这是我的 foreach 但我不确定我应该循环什么。请帮忙。

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++;
}
4

1 回答 1

0

尝试更改此行:

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

至:

foreach(resultCheckinsJson.data 中的动态行)

然后得到这样的属性:

row.name
于 2013-08-14T15:58:03.460 回答