Wednesday, April 09, 2014

Reading json easily with C#

You need Newtonsoft.Json dll and use of "dynamic" type in C# to do below.
This code gets follower count from Twitter api without the need to create extra classes
to load json data  : 
 
var wc = new WebClient(); 
string json= wc.DownloadString(url);

         dynamic obj = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(json); 
        int? twFollowerCount =obj.followers_count;

No comments:

Post a Comment