Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Part 11: Working with JSON Data

Embed code for this video

Copy the code above to embed our video on your website/blog.

Close

Video format

Option selected may change based on video formats available and browser capability.

Close

Download

Right click “Save as…”

In this lesson we talk about the JSON data format and look at the code in the RecipeDataSource.cs that loads and parses through that data to create instances of our RecipeDataItem and RecipeDataCollection objects.
 
Resources
 
 

Tags:

Follow the Discussion

  • wow!, stop being cool and change the background of this video.
    Viewing this online is terrible. The distraction is unbelievable. Keep it simple man, go regular next time. I can't follow your coolness here at all.

    Thanks anyway

  • What do you mean by "background" and "cool"?  Are you attempting to stream the video and you're only seeing garbled text?  If so please DOWNLOAD and view the video locally.  The video was created in high def 1280x720 and you may not have sufficient bandwidth to stream the video.  Silverlight throttles your playback experience based on the speed on your Internet connection.  If that's NOT what you're talking about you'll need to be more explicit in exactly what you're referring to so I can help.

  • i just downloaded (high quality mp4) this it works perfect for me, the font colors and background is awesome, loooveeee vs 2012 !!! (we shud rename it to vs 2013 its not fair we are in 2013 so quickly).

  • Jason ShortJason Short

    I don't know why this code was written with all these switch statements. Why not just deserialize the json into a class? This seems much more tightly coupled, you could have just used CSV files.

  • @Jason Short: Hi Jason, I only offer two replies to your question / comment ... (1) I think the authors of the Hands On Labs wanted to re-use the JSON file for C# and JavaScript versions.  So, rather than have the JavaScript version access a CSV, they chose to have the C# version access a JSON file.  (2) There are ways to map JSON objects and properties to C# classes and properties, but the most popular way I found was to use an open source library, JSON.NET ... take a look at this:

    http://stackoverflow.com/questions/2246694/how-to-convert-json-object-to-custom-c-sharp-object

    So, I suspect that the HOL authors made a choice ... do they introduce a new library into the mix and require people to learn enough of it to be productive, OR do they just power through and parse the JSON manually.  They chose the latter.   Again, I'm just assuming this was their thought process.  Thank you!

     

    Edit: later that day ... After snooping around a little more, there's another option for JSON serialization, although I didn't really try it myself and don't know if it would work in a Windows Store app ... 

    http://blogs.microsoft.co.il/blogs/pini_dayan/archive/2009/03/12/convert-objects-to-json-in-c-using-javascriptserializer.aspx

  • Wow I understood your fundamental C# series perfectly, but I am finding this series very difficult. 

    I would have liked it if you started a project from scratch building all the classes and interfaces to get a deep understanding of what is going on, as your teaching methods are second to none so far when comparing to Pluralsight and TekPub tutorials. But I understand you may be a very busy man to do such a series. 

  • @ah07171: Thanks for the feedback ... admittedly, because there was an end goal in mind (i.e., the creation of a real app) this got off the ground much faster than the other series.  At what point did you start running into some friction?  Are you also using the Hands On Lab text or just the videos?

    Since you commented on this video, I'm going to assume this was the straw that broke the camel's back, so to speak.  There was a lot of complexity around working with the JSON and that accounted for the majority of the code.  The JavaScript version of this video was literally one line of code, so this was a trade off -- the team that created the Hands On Lab wanted to re-use the JSON data necessitating a lot of parsing and massaging of the data.

    Here's hoping you'll not get discouraged and will continue on with the series.

  • , BobTabor wrote

    @ah07171: Thanks for the feedback ... admittedly, because there was an end goal in mind (i.e., the creation of a real app) this got off the ground much faster than the other series.  At what point did you start running into some friction?  Are you also using the Hands On Lab text or just the videos?

    Since you commented on this video, I'm going to assume this was the straw that broke the camel's back, so to speak.  There was a lot of complexity around working with the JSON and that accounted for the majority of the code.  The JavaScript version of this video was literally one line of code, so this was a trade off -- the team that created the Hands On Lab wanted to re-use the JSON data necessitating a lot of parsing and massaging of the data.

    Here's hoping you'll not get discouraged and will continue on with the series.

     

    Thanks for the reply.

    It was actually some of the previous videos which I got stuck with, the classes, the interfaces some methods...etc, I do understand I have to really break it down and struggle with it.

    I also do understand going into detail with everything would have taken a lot more time and that hoping for a detailed tutorial starting from scratch on a project where the end goal is an app of this complexity was going to be too much. Also this project did require the use of a template.

    However I think I may just start on my own project soon, build something big from scratch something that I may need, instead of hoping to find someone building their own project and making a tutorial on it from scratch, like I have been hoping for hahaha.

    Anyway I will finish this series hoping it makes sense to me at some point, and I'm sure I will pick up a few new things along the way. 

    I look forward to your next series. 

  • reeganreegan

    how to display json string to table formate usin c#?

  • @reegan: Check this out ... it's specifically for WIndows Phone, HOWEVER since it's XAML it will be similar.  

    http://stackoverflow.com/questions/14153659/how-can-i-bind-data-into-xaml-windows-phone

    Hope that helps!

  • RaghuramanRaghuraman

    Hi,
    If I try to parse a correct json file it is working fine, at the same time if I parse an invalid json file it throws an Exception and I am able to handle it. However If I have a json file which is partially correct it doesn't throw an exception and It shows a blank screen. Could you please help me fix this bug.

Remove this comment

Remove this thread

close

Comment on the Post

Already have a Channel 9 account? Please sign in