Cool LINQ over JSON..........In MonoDroid no less

I was working on some json/rest web services written in windows communication foundation (wcf).  I wanted to use the System.Json namespace to do some of this.  I made an http web request asynchronously.  In my call back method, I have following code doing a linq query over this json result.

System.Json.JsonArray jsonArray = (System.Json.JsonArray)System.Json.JsonArray.Load(strm);
var twt = (from jsonTweet in jsonArray
            select new Tweet
            {

                ProfileImage = jsonTweet["ProfileImage"].ToString(),
                Status = jsonTweet["Status"].ToString(),
                StatusDate = jsonTweet["StatusDate"],
                StatusId = Convert.ToInt64(jsonTweet["StatusId"].ToString()),
                UserName = jsonTweet["UserName"].ToString()
            }).ToList<Tweet>(); 

Now I have a list of type Tweet. 

fyi, I didn't need to do a .ToList<> for this, but I was doing something else.

I hope this helps you out in your coding

No Comments