Retrieving and Deserializing JSON in Your Xamarin.Forms App

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ส.ค. 2024
  • Getting data from a remote server or REST API is a big part of any app. In this video we will learn how to get JSON data from an ASP.NET Core Web API and deserialize that. From there we will see how to show this in a CollectionView by using DataTemplates.
    💝 Join this channel to get access to perks:
    / @jfversluis
    🛑 Don't forget to subscribe to my channel for more cool content: th-cam.com/users/GeraldVerslui...
    🐦 Follow me on Twitter: / jfversluis
    🔗 Links
    Sample code repo: github.com/jfversluis/XFGetti...
    Disable HTTPS Android: devblogs.microsoft.com/xamari...
    Multiple run configuration: blog.verslu.is/productivity/v...
    QuickType: quicktype.io
    Disable HTTPS iOS & Android: • Uploading Files From a...
    Xamarin Forms Repo: github.com/xamarin/Xamarin.Forms
    ⏱ Timestamps
    0:00 Intro
    0:27 Sample App Outline
    1:26 Sample ASP.NET Core Server Project Outline
    4:00 Generate C# Class From JSON Data
    7:18 Implement Getting JSON from Server
    9:52 Important Note About Localhost!
    11:48 Testing With HTTPS/SSL
    14:23 Deserialize JSON Data
    16:00 Run Sample! ... And Fail :(
    17:00 Setup Server Sample App For Outside Connections
    17:47 Run Sample! Great Success!
    18:14 Making the Data Pretty With DataTemplates
    19:37 Pretty Sample App
    20:06 Outro
    🎥 Video edited with Camtasia (ref): techsmith.z6rjha.net/AJoeD
    🙋‍♂️ Also find my...
    Twitter: / jfversluis
    Blog: blog.verslu.is
    Twitch: / jfversluis
    All the rest: jfversluis.dev
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 86

  • @jfversluis
    @jfversluis  2 ปีที่แล้ว

    Want to learn more about uploading data to a REST API? Check out this video right here: th-cam.com/video/KPDGtLeNClQ/w-d-xo.html

  • @robertbrown7478
    @robertbrown7478 3 ปีที่แล้ว +1

    Awesome tutorial! I love how you tied it in with the Collection View and that you didn't edit out the mistakes so we know what the potential pitfalls are. Thanks so much!!!

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว +1

      Thank you Robert! Yeah, unless it's a major catastrofe I'll just let it in so you can also learn from my mistakes :)
      I think it's important to realize no one is perfect and hopefully when someone runs into the same thing they now learned 2 things from this video!

  • @marox88
    @marox88 3 ปีที่แล้ว +1

    Thank You for remembering and made what I was asking for :)) Gerald You are FANTASTIC!! :) And please make this DataTemplate :D

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Of course I did! 😌 DataTemplates is also on the list!

  • @levkilic
    @levkilic 3 ปีที่แล้ว

    Thank you Gerald for this great video! You explained the topic in a simple way, not lost in details.

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      That’s great to hear, thank you Levent!

  • @androidsavior
    @androidsavior 3 ปีที่แล้ว

    This is great ! , keep it up man

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Will do! Thank you!

  • @onlysexist
    @onlysexist 2 ปีที่แล้ว

    Excellent, just excellent. More than Exccellent my friend. This is what i was looking for. From Dominican Republic: Excellent

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      That is amazing to hear, thank you so much!

  • @codigoadictivo
    @codigoadictivo 3 ปีที่แล้ว

    Coool, nice video 👍🏽

  • @abdelrahmanalasal6801
    @abdelrahmanalasal6801 2 ปีที่แล้ว

    Thanks Gerald

  • @mo7amedh.m264
    @mo7amedh.m264 3 ปีที่แล้ว

    You really really really the best 👏

  • @chosenvan
    @chosenvan ปีที่แล้ว

    Thank you very much.. I needed this.. solved all my problems ;)

    • @jfversluis
      @jfversluis  ปีที่แล้ว +1

      Thank is great! Thank you so much for letting me know :D

  • @YoUserExp
    @YoUserExp 3 ปีที่แล้ว

    Great stuff! Nice work on the stream yesterday talking about the community toolkit as well. Thank you for all of the information. If possible I'd like to ask for a video implementing MQTT communication if you are in need of video ideas.

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Thank you Jeremy! It was so much fun to do!
      MQTT in itself or specific to Xamarin? Not something I'm very familiar with so wouldn't hold my breath, but who knows! I appreciate the suggestion :)

    • @YoUserExp
      @YoUserExp 3 ปีที่แล้ว +1

      @@jfversluis Thanks for the reply. I was thinking of Xamarin specifically. I currently use websockets but it seems to be a little overkill for my use case. Also, In the toolkit do you think we'll ever have a semi official Bluetooth library. If not is there one you recommend?

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Not in the foreseeable future I think. Do you know about Shiny?

    • @YoUserExp
      @YoUserExp 3 ปีที่แล้ว

      @@jfversluis I had looked into it but it was only in prerelease when I was originally developing my app. Have you had a good experience with it?

  • @Tamer_Ali
    @Tamer_Ali 3 ปีที่แล้ว

    Hi Gerald,
    Awesome video tutorial
    I hope you talk about how to use Localization in Xamarin Forms and how to change the app / page / control flow direction RTL/LTR based on localization.
    Thanks

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว +1

      Great suggestion! Thank you for watching!

  • @dancluderay1304
    @dancluderay1304 3 ปีที่แล้ว

    Very good

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Thank you Dan! And thank you for being a member! Very much appreciated!

  • @cissemy
    @cissemy 3 ปีที่แล้ว +1

    Great course.
    How can I add pagination and filter my collectionview ?
    Thanks

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Here is at least a tutorial on how to add pagination: doumer.me/infinite-scroll-with-the-xamarin-forms-collection-view/

    • @cissemy
      @cissemy 3 ปีที่แล้ว

      @@jfversluis
      Thanks

  • @lemoncrazedcamel
    @lemoncrazedcamel 3 ปีที่แล้ว

    A great note for anyone on windows, you can use the special paste functionality of vs2019 to create the serializable class instead of using a website

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Absolutely! Didn't I mention that in the video?! Did I forget? Because it's such a good feature! I should record productivity tips :D
      Thanks for adding this!

    • @lemoncrazedcamel
      @lemoncrazedcamel 3 ปีที่แล้ว +1

      @@jfversluis I think you did I just jumped the gun on my comment! :D and a productivity tools and tips video would be great!

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว +1

      No worries! Better one time too many!
      I’ll think about those productivity ones... it’s a bit of a blind spot probably because I use a lot of them without even noticing anymore 😄

  • @25kyro
    @25kyro 3 ปีที่แล้ว

    Awesome! But noticed you said I want to keep it simple without Data Binding, but could you show us how to do with Binding also!

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Sure thing! What is it you'd like to see exactly?

  • @bastiantokusumajaya4337
    @bastiantokusumajaya4337 2 ปีที่แล้ว

    Hello, can i ask, i have already searched around your channel and can't find the video u mentioned about sending data to rest api, which i needed, can you please give me the link for that video you mention in the beginning of this video?

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      Whoops sorry about that, I was referring to this one: th-cam.com/video/KPDGtLeNClQ/w-d-xo.html

  • @chrisdroney8141
    @chrisdroney8141 3 ปีที่แล้ว +1

    Hey, thanks for the tutorial! It hasn't been very easy for me to find good tutorials for the xamarin.forms framework. The sample code repo link seems to be dead, is there any chance you've renamed that project since uploading?

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว +1

      You'll never believe it... I forgot to set the repo to public and no one ever noticed :D
      Made it public now! Hope it helps!

    • @chrisdroney8141
      @chrisdroney8141 3 ปีที่แล้ว

      @@jfversluis Thanks, I appreciate it!

  • @Elsa-jw3xe
    @Elsa-jw3xe 3 ปีที่แล้ว +1

    Great video Gerald. Could you perhaps make a video how to work with libraries?

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      A library to work with libraries? 😉 I assume you mean video! But what do you want to know about working with libraries?

    • @Elsa-jw3xe
      @Elsa-jw3xe 3 ปีที่แล้ว

      @@jfversluis lol yes, i was too quick... But would be nice if you could do a video about that. Been thinking myself about a login which i could use in several projects and then only change the layout. But perhaps thats too much to ask haha.

  • @dancluderay1304
    @dancluderay1304 3 ปีที่แล้ว

    Would be great to see a video on Bluetooth beacons and triggering events

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      If only Apple would release those AirTags :D

  • @AMIRKHAN-dm2fm
    @AMIRKHAN-dm2fm 3 ปีที่แล้ว

    great
    i am waiting for app center tutorials😉
    and please try to make tutorial series on MVVM and clean architecture or best practices.

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว +1

      Working on it!

    • @AMIRKHAN-dm2fm
      @AMIRKHAN-dm2fm 3 ปีที่แล้ว

      @@jfversluis Thanks😊

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว +1

      What do you want to know about MVVM?

    • @AMIRKHAN-dm2fm
      @AMIRKHAN-dm2fm 3 ปีที่แล้ว

      @@jfversluis sir all advance concepts.

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Can you make that more concrete? What is advanced for one person might now be advanced for another :)

  • @hossamal-deenhamedal-sayyd9166
    @hossamal-deenhamedal-sayyd9166 3 ปีที่แล้ว

    How to Make This Function And Get The Response And displayed in collection View In Fresh MVVM ?

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      FreshMvvm shouldn't matter in this case. Just make sure to put the data in a ObservableCollection and use that as the source for your CollectionView with databinding

  • @jaskodemic9705
    @jaskodemic9705 3 ปีที่แล้ว +1

    Thanks for that but can u explain how u get the data if json hava child ?

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว +1

      If you paste that into QuickType it will also do that for you. Basically just create another object and add that as a property :) I can do another video on that

    • @annbrady2310
      @annbrady2310 3 ปีที่แล้ว +1

      @@jfversluis A video on this would be greatly appreciated.

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      What is de trouble you’re having with it?

  • @divangerber7897
    @divangerber7897 3 ปีที่แล้ว

    Wait, how did you get a response in postman on /weatherforecast without running the application in Visual Studio First? I get a Error: connect ECONNREFUSED "IP adress" ..

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว +1

      Sorry if I made it seem like it isn’t running. It definitely has to run or be hosted somewhere for this to work :)

    • @divangerber7897
      @divangerber7897 3 ปีที่แล้ว

      @@jfversluis Ok so I am implementing what I learn from your uploads, how do I host my api (to a sql express database) so that remote devices can do CRUD operations to and from the database through the XAMARIN.Forms Cross-platform app?

  • @jordanreighn3143
    @jordanreighn3143 2 ปีที่แล้ว

    I get a Unexpected character encountered while parsing value. What could this mean?

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      You’re probably getting HTML back instead of JSON so something about the request or response isn’t right. Try with a tool like postman

  • @keimmeraltuve8452
    @keimmeraltuve8452 2 ปีที่แล้ว

    I cant retrieve from a json link because the method get does not return anithing, the api has an .json file what should i do in that situation?

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      Not sure what you mean. You mean it wants do download a .json file rather than sending you the JSON content directly? Read the file in memory and deserialize from there :)

    • @keimmeraltuve8452
      @keimmeraltuve8452 2 ปีที่แล้ว

      @@jfversluis sorry, english is not my main language, but thanks for the explanation, I figured it out, great video thanks for the explanation

  • @tomoorizardo745
    @tomoorizardo745 3 ปีที่แล้ว

    bro please make one with images + json data. for example a product with image using webapi Or a user with profile picture that is uploaded to a webapi.

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว +1

      It’s probably easier to do that separately. If you look at apps they mostly let you add all the “text data” like you profile info first, and you tap on your profile image to set that separately.
      Even if that’s not what you want, make the UI so that it looks as one but do two calls in the background one for the data and one for the image.
      I’ll see if I can get to a video that combines it, hopefully this helps in the meantime

    • @tomoorizardo745
      @tomoorizardo745 3 ปีที่แล้ว

      @@jfversluis thank you so much bro

  • @DhirenPathak
    @DhirenPathak 2 ปีที่แล้ว

    please also put Web API Consume in MAUI Blazor App

    • @jfversluis
      @jfversluis  2 ปีที่แล้ว

      That’s in there but should be no different than doing it in any other type of app :)

  • @LobsterHarry
    @LobsterHarry 3 ปีที่แล้ว

    That was a little too Quick & Dirty in my Opinion. Fortunately I knew everything already ! ;-)

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว

      Oh no! Why’s that? You feel it’s going to fast for people to follow? Or you mean you’d like to see it done a bit more the right way than just creating an HttpClient all the time?

  • @_samirdahal
    @_samirdahal 3 ปีที่แล้ว

    What if we have different naming convention in our json object and c# class properties? Can it still able to deserialize it?
    app.quicktype.io/ this was a pro tip. Thanks!

    • @jfversluis
      @jfversluis  3 ปีที่แล้ว +1

      Great! Glad you learned something! If it’s different you can use the JsonProperty attribute on your properties. See for example: www.jerriepelser.com/blog/deserialize-different-json-object-same-class/

    • @_samirdahal
      @_samirdahal 3 ปีที่แล้ว +1

      @@jfversluis Thanks! I got it.