1

Daniel Crenna の TweetSharp http://github.com/danielcrenna/tweetsharpを使用しています。

TwitterStatus をファイルにシリアル化するには、コードを使用します

sw.WriteLine(JsonConvert.SerializeObject(twitterStatus));

テキストを生成する

{"Id":288653019971727360,"InReplyToUserId":null,"InReplyToStatusId":null,"InReplyToScreenName":null,"truncated":false,"favorited":false,"Text":"Found the bug, dear old regular expressions","Source":"web","User":{"Id":1148081,"FollowersCount":793,"Name":"Tim Regan","Description": [...]

(NB、診断に役立つ場合を除き、すべてを含めませんか?)

TwitterStatus を逆シリアル化するための私のコード行は

var tweet = (TwitterStatus)JsonConvert.DeserializeObject(line);

しかし、それはエラーを与えます

System.InvalidCastException was unhandled HResult=-2147467262 Message=Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'TweetSharp.TwitterStatus'. Source=TweetColorMVVM StackTrace: at TweetColorMVVM.Model.Tweets.LoadSavedTweets(String screenName) in c:\TFSCML\Users\Tim\MSR.Makefest\TwitterColor\TweetColorMVVM\Model\Tweets.cs:line 132 at TweetColorMVVM.Model.Tweets.LoadTweets(Object state) in c:\TFSCML\Users\Tim\MSR.Makefest\TwitterColor\TweetColorMVVM\Model\Tweets.cs:line 78 at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

誰が私が間違っているかを見ることができますか?

4

1 に答える 1

1

私は書くべきだった:

var tweet = (TwitterStatus)JsonConvert.DeserializeObject(line, typeof(TwitterStatus));

それは今動作します。

于 2013-01-08T22:43:37.987 に答える