May 27, 2013

Tesla -- Instant Messaging for Teams

Getting group-chat to work is hard. Getting group-chat to work easily is immensely hard. That's when a friend told me about his app, is Instant Messaging for Teams/Groups. Where stands out from the rest is its intuitive design. Its very simple and easy to use. No lengthy forms to fill. Just click 'Guest Login' and you are taken into the app. You can register if you like it. Else just logout and forget about it.

It's a 100% free service (ad-free too) and it seems reliable, stable and secure. The engineers at tell me that its built with node.js and can handle many many times the concurrent connections compared to existing technologies like XMPP. (Google just gave up on XMPP just a few days back - Link) is still an alpha release, with more features like desktop notifications, etc lined up.

Experience it and let me know your thoughts.

Oct 1, 2012

Parsing JSON in a Windows Phone Application

I see questions regarding JSON parsing/deserializing almost everyday in Stackoverflow. Hence decided to write a blog post to show you how to easily parse JSON strings in Windows Phone applications.

***Please read entire blog for a complete overview before implementing in your applications***

I would like to divide this post into 2 categories.
One is, where you will have to parse a similar json data in many places in your application or you will use the parsed data in many instances of your code
Other is, you just parse the data once, get your values and no need of the data else where in your project i.e one time usage.


Step 1: Go to Json2Csharp site and paste either your entire JSON string or URL to the JSON and click on Generate button. This creates all the required classes for your JSON response.

I am taking this sample json data

{"MyBookList": [{"ID":5,"TYPE":"History","TITLE":"XYZbook","PRICE":"200","IMAGE":"Ekannoborti.jpg","DOWNLOADLINK":""}],"success":3}

And here are the classes generated
public class MyBookList
    public int ID { get; set; }
    public string TYPE { get; set; }
    public string TITLE { get; set; }
    public string PRICE { get; set; }
    public string IMAGE { get; set; }
    public string DOWNLOADLINK { get; set; }

public class RootObject
    public List<MyBookList> MyBookList { get; set; }
    public int success { get; set; }
Now place this classes somewhere in your project, so that they are available in all the locations you require them.

Step 2: ( Here I am assuming that you get your json from a web service)
Make a web request to get the JSON response

WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri(""));

And then in the response handler, use the following code to parse the data and convert into classes

void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    var rootObject = JsonConvert.DeserializeObject<RootObject>(e.Result);

    foreach (var book in rootObject.MyBookList)
    } }

There you go, you can play with the response classes and data bind them with the UI elements :)


Here as your requirement is one time parsing and one time usage, instead of storing them in unnecessary classes, we just wisely parse the data and get the task done.

Consider this sample,

String jsonData = @"{""MyBookList"": [{""ID"":5,""TYPE"":""History"",""TITLE"":""XYZbook"",""PRICE"":""200"",""IMAGE"":""Ekannoborti.jpg"",""DOWNLOADLINK"":""""}],""success"":3}";

And inorder to get the title of each book here

JObject obj = JObject.Parse(jsonData);
JArray jarr = (JArray)obj["MyBookList"];
string bookTitle = (string)jarr[0]["TITLE"]; //To get the title of First book
foreach(var item in jarr)
     Console.WriteLine(item["TITLE"]); //Gets the title of each book in the list

NOTE : For both the cases, I have used for parsing the json data. You can get it from this Nuget package. And if you dont know how to install and use a Nuget package, Check Here
Hope it helps. Please dont forget to +1 or leave a comment.
Thank you
View Kishor Chandra's profile on LinkedIn