2011-01-24 132 views
1

https://graph.facebook.com/331218348435 我想发布'场地'信息,如何插入一个子节点/字典到postArgs?我可以得到的基本信息如下词典与字典<字符串,字符串>

Facebook.FacebookAPI api = new Facebook.FacebookAPI(GetAccessToken(code)); 

Dictionary<string, string> postArgs = new Dictionary<string, string>(); 
postArgs["name"] = myEvent.Title; 
postArgs["description"] = myEvent.Content; 
postArgs["start_time"] = myEvent.DateStart; 
postArgs["end_time"] = myEvent.DateEnd; 
postArgs["location"] = myEvent.Location; //myEvent.City;//"; 
postArgs["page_id"] = "1234567"; 

// Dictionary<string, string> postVenue = new Dictionary<string, string>(); 
// postVenue["city"] = myEvent.City; 
// postVenue["state"] = myEvent.County; 
// postVenue["country"] = "United Kingdom"; 
// postVenue["latitude"] = myEvent.Latitude; 
// postVenue["longitude"] = myEvent.Longitude; 

// here I need to add postVenue to postArgs as a child. 

api.Post("/12345676788/events", postArgs); 

感谢您的时间。

回答

1

您不能在此处放置postArgs中的字典,因为您声明它具有字符串的值类型。代码

Dictionary<string, string> postArgs = new Dictionary<string, string>() 

指示它具有字符串类型和字符串类型值的键。如果你想成为能够storea类型的混合,你想要的东西,如:

Dictionary<string, Object> postArgs = new Dictionary<string, Object>() 

然而,这需要你为他们退出了字典投值。

2

从你的代码,我想到的是邮政的签名是:

void Post(string, Dictionary<string,string>) 

,如果是这样的话,那么你就需要序列化你的字典(postVenue)和序列化的字符串添加到字典中。然后,接受帖子的代码需要反序列化,但是由于您在API上调用方法,我怀疑您可能无法向被叫方提供反序列化信息。

您是否管理将使用发布参数的代码以及发布参数的代码?

序列化的代码可能是:

var pairs = postVenue.Select(pair=>pair.Key + ":" + Pair.Value).ToArray(); 
var venues = string.Join(",",pairs); 

你可以再添加它像这样:

postArgs.Add("venues",venues); 

然后deseialization将

var venues = postArgs["venues"] 
var postVenue = (from pair in venues.Split(',') 
       select pair.Split(':') 
       ).ToDictionary(pair => pair[0],pair=>pair[1]); 
相关问题