Parsing A JSON was never that easy

Hello guys, once again i am here to give you clear about, how you can parse JSON into the visible material into your application in presentable form. So, parsing JSON been hectic, I know, but we are going to make it easy together. To go through parsing things please follow the following steps after opening simple blank windows phone app :

  1.  First of all you need to get the JSON file of some website and get it validated from http://jsonlint.com/.
  2. After you successfully validated the JSON, Now, you need to get it in the form of clases in order to get it done. So, for classes things you can convert it manually or paste the link in following to get the C-sharp classes code. json2charp1b
  3. you can use the link below to make it checked for your application  http://yts.re/api/list.json
  4. Add the class now in you project named it as RootObject  and put all the copied code from json2csharp into it.
  5. Now, simply put the button into your application to make things work manually and add the following code in it

    WebClient web = new WebClient();
    web.DownloadStringCompleted += web_DownloadStringCompleted;

    web.DownloadStringAsync(new Uri(“http://yts.re/api/list.json”));

  6. Now, in Routed event of downloadStringCompleted add the following
    Note: here RootObject is class name movieList is the list placed into RootObject which is a list of another class named as MovieList in RootObject.cs
    change it according to your requirement


    var rootObject = JsonConvert.DeserializeObject<RootObject>(e.Result);

    foreach (MovieList abc in rootObject.movieList)
    {

    MessageBox.Show(abc.Title.ToString());
    }

  7. Now that you will see you can view the title in every object on the messageBox alert, which means you succesfully parsed the string.

    if you get any problem you can reach me through comments, thanks

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s