我有下面的代码。
该行string content = twitterMsg.text;
正在为 twitterMsg 创建错误“使用未分配的局部变量”。我似乎无法访问我收藏TwitterSearchResponse.results.text
中的字段。DataContractJsonSerializer<TwitterMain>
TwitterSearchResponse.results
是一个数组(一组对象属性),其中包含几个字符串字段,名称如text
和user_info
。
有人能帮忙吗??
更新了下面的代码。我仍然很困惑为什么我不能TwitterSearchResponse.results
正确地迭代我的并分配content = twitterMsg.text
对于它的价值,这是我的 DataContractJsonSerializer 方法:
String url = String.Format("http://search.twitter.com/search.json?q={0}&rpp=20", Server.UrlEncode(txtSearchFor.Text));
// parse the JSON data
using (MemoryStream ms = new MemoryStream(wc.DownloadData(url)))
{
DataContractJsonSerializer jsonSerializer =
new DataContractJsonSerializer(typeof(TwitterMain));
TwitterSearchResponse = jsonSerializer.ReadObject(ms) as TwitterMain; // read as JSON and map as TwitterOut
}
这是问题所在的原始发布代码。
public List<MatchCollection> returnMatches(DataContractJsonSerializer<TwitterMain> TwitterSearchResponse)
{
List<MatchCollection> messageLinks = new List<MatchCollection>();
foreach (TwitterResult twitterMsg in TwitterSearchResponse.results)
{
string content = twitterMsg.text;
// capture internet protocol pre-fixed words from message
string pattern = @"...";
messageLinks.Add(Regex.Matches(content, pattern, RegexOptions.IgnoreCase));
// capture @username twitter users from message
string atUsernamePattern = @"@([a-zA-Z0-9-_]+)";
MatchCollection PeopleMatches = Regex.Matches(content, atUsernamePattern, RegexOptions.IgnoreCase);
}
return messageLinks;
}