我正在使用多种查询来获取朋友签到。我有查询按预期返回数据,但我想要做的是创建一个包含每个查询元素的DataTable。我只有3个结果,但数据中至少有一百个。除了我知道我的循环不正确之外,我不确定我做错了什么。具有讽刺意味的是,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++;
}
答案 0 :(得分:0)
尝试更改此行:
foreach (var row in resultCheckinsJson["data"].Children())
要:
foreach(resultCheckinsJson.data中的动态行)
然后得到这样的属性:
row.name