我正在使用 TweetSharp 来检索推文,这些推文又使用 Newtonsoft 的 JSON.NET。这是应用程序代码,非常简单。
ListTweetsOnUserTimelineOptions listTweetsOnUserTimelineOptions =
new ListTweetsOnUserTimelineOptions();
listTweetsOnUserTimelineOptions.ScreenName = "MarilynDenisCTV";
listTweetsOnUserTimelineOptions.IncludeRts = false;
var tweets = twitterService.ListTweetsOnUserTimeline(listTweetsOnUserTimelineOptions).Take(50);
有一条推文给我带来了麻烦。我得到的异常出现在 TweetSharp 源代码中的这行代码中。
public virtual object DeserializeJson(string content, Type type)
{
using (var stringReader = new StringReader(content))
{
using (var jsonTextReader = new JsonTextReader(stringReader))
{
return _serializer.Deserialize(jsonTextReader, type);
}
}
}
这是我得到的例外
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'TweetSharp.TwitterStatus' because the type requires a JSON
object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a
type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array.
JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path '',
我从 TweetSharp 下载了最新的源代码,但这似乎没有帮助,任何想法为什么?还有一件事,一个问题推文以 [{"created_at": "Sun Nov 03 21:44:51 +0000 2013" 开头,应该是 {"created_at": "Sun Nov 03 21:44:51 +0000 2013 ",它有额外的方括号。