1

I am using Tweetinvi to get Twitter stream, quite easy/friendly to use but unable to parse Json to a Tweet. Can anybody help me converting/parsing args.Json to a Tweet (using Newtonsoft.json)?

filteredStream.JsonObjectReceived += (sender, args) =>
{
    var tweet = JsonConvert.DeserializeObject<Tweetinvi.Core.Interfaces.ITweet>(args.Json);
};

Above line ends up with following Error because ITweet is an interface:

Could not create an instance of type Tweetinvi.Core.Interfaces.ITweet. Type is an interface or abstract class and cannot be instantiated
theGeekster
  • 6,081
  • 12
  • 35
  • 47
  • the error message is clear. Instead of interface, use concrete class provided in the library if any, or try create a class that inherits `ITweet` – har07 May 01 '14 at 07:44

1 Answers1

2

Just use the method that is already implemented:

 fs.MatchingTweetReceived += (sender, args) => { var tweet = args.Tweet; };

If you really want to do the Json conversion on your own you can do the following:

 var jsonConvert = TweetinviContainer.Resolve<IJsonObjectConverter>();
 var tweetDTO = jsonConvert.DeserializeObject<ITweetDTO>(json);
 var tweet = Tweet.GenerateTweetFromDTO(tweetDTO);
user2465083
  • 595
  • 3
  • 12