Deserialize JSON Data to Custom C# Class Objects using Newtonsoft.

Поделиться
HTML-код
  • Опубликовано: 19 окт 2024

Комментарии • 86

  • @elaprimo1
    @elaprimo1 2 года назад +16

    oh my dear god, I've watched like 30 different videos about how to deserialize a JSON properly, and this is the first one that explains it so well and so detailed. and not only a simple JSON, multiple difficulty levels. Just perfect man, thanks.

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад +1

      Hey Raelth, I am so happy you found the right video to help solve your problem. And thank you for taking the time to write a comment about your journey. I’m so lucky to be part of it.

  • @juruvaper4173
    @juruvaper4173 8 месяцев назад

    I've never seen better tutorial covering this topic, awesome. I was struggling a lot and it turned out to be quite easy - thanks

    • @SoftwareNuggets
      @SoftwareNuggets  8 месяцев назад

      Thank you for the compliment, much appreciated.

  • @twotinytrees9794
    @twotinytrees9794 2 года назад +1

    Very good video! A couple things that may help others, though: you can shortcut the whole process by copying the JSON and going to your class in Visual Studio and clicking Edit > Past Special > Paste JSON as Classes. Boom, job done. Also, I don't think the comment about case sensitivity with properties is accurate, as I always go back through and change my properties to uppercase to keep them standardized.

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад +1

      Hey Two TinyTrees,
      Thanks for leaving a great message that I'm sure will help others. You are 100% correct about CASE SENSITIVITY, by default Newtonsoft is case insensitive.
      The ShortCut is also a great tip.
      Several months ago, another distinguished viewer, much like yourself, showed me that nugget, and then a couple days ago, I made a video about that shortcut.
      Here is a link to my video: ruclips.net/video/5NOhai66okg/видео.html
      Thanks again.

  • @michaelnimley8676
    @michaelnimley8676 Год назад

    Man, you've got a gift. Extremely good tutorial.

    • @SoftwareNuggets
      @SoftwareNuggets  Год назад

      Hey Michael, thanks for the very kind comment. Glad to hear this video was useful.

  • @saidsabri1861
    @saidsabri1861 2 года назад

    I do not usually comment on videos, but this one is just amazing, thank you so much

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      Hey Said, I am grateful enough you found my channel and viewed this video, but your comment is heart felt. thank you.

  • @morg573
    @morg573 Год назад

    You finally helped me understand this after days of trying. Thank you for this video.

    • @SoftwareNuggets
      @SoftwareNuggets  Год назад +1

      What was the issue you were having. I’m sure other viewers are having the same problem. Thanks for leaving a message.

    • @morg573
      @morg573 Год назад +1

      @@SoftwareNuggets I didn't understand that the class properties and json attributes had to have the exact same name. nor did i understand what went inside the after DeserializeObject.

    • @SoftwareNuggets
      @SoftwareNuggets  Год назад +1

      Thanks for sharing. Glad to hear you are own your way now!

  • @radheshyamgupta8656
    @radheshyamgupta8656 2 года назад

    It's very interesting video, i really like it. Thank for shared this

  • @MrHussain99x
    @MrHussain99x 2 года назад

    Very useful tutorial!! Really helped me with my dissertation, Thank you!

  • @essamce1436
    @essamce1436 2 года назад +2

    You are an amazing teaher.

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      Hey Essam, thank you for your comment. I hope this video was able to help.

  • @SoftwareNuggets
    @SoftwareNuggets  3 года назад +3

    Hey Team, here is the source code to Example #4. Enjoy.

    • @SoftwareNuggets
      @SoftwareNuggets  3 года назад

      Here is program.cs ----
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using Newtonsoft.Json;
      using Newtonsoft.Json.Serialization;
      using Newtonsoft.Json.Converters;
      using Newtonsoft.Json.Linq;
      using System.IO;
      namespace ModelThatJSON
      {
      class Program
      {
      static void Main(string[] args)
      {
      string fileName =
      @"C:\Users\scottj.SCOTTWIN10-2\source
      epos\ModelThatJSON\ModelThatJSON\sample.json";
      string jsonText = File.ReadAllText(fileName);
      var data = Newtonsoft.Json.
      JsonConvert.DeserializeObject(jsonText);
      }
      }
      }

    • @SoftwareNuggets
      @SoftwareNuggets  3 года назад

      Here is MyModel.cs --
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      namespace ModelThatJSON
      {
      public class MyModel
      {
      public int cid { get; set; }
      public string entityName { get; set; }
      public _accounts accounts { get; set; }
      }

      public class _accounts
      {
      public worldInvestor usa { get; set; }
      public worldInvestor slovakia { get; set; }
      public worldInvestor ecuador { get; set; }
      public worldInvestor mexico { get; set; }
      }
      public class worldInvestor
      {
      public _EntityStockShares entityStockShares;
      }

      public class _EntityStockShares
      {
      public string label { get; set; }
      public string desc { get; set; }
      public _units units { get; set; }
      }
      public class _units
      {
      public _trades[] trades { get; set; }
      }
      public class _trades
      {
      public int acct { get; set; }
      public DateTime dateOfTrade { get; set; }
      public string ticker { get; set; }
      public string tranType { get; set; }
      public int qty { get; set; }
      public decimal costPerShare { get; set; }
      }
      }

    • @SoftwareNuggets
      @SoftwareNuggets  3 года назад +1

      Here is the sample JSON is used in this demo #4 --
      {
      "cid": 750,
      "entityName": "Software Nuggets",
      "accounts": {
      "usa": {
      "entityStockShares": {
      "label": "Common Stock, that is outstanding",
      "desc": "# of shares each customer holds",
      "units": {
      "trades": [
      {
      "acct": 101,
      "dateOfTrade": "2021-09-15",
      "ticker": "MSFT",
      "tranType": "Buy",
      "qty": 12,
      "costPerShare": 304.82
      },
      {
      "acct": 101,
      "dateOfTrade": "2021-09-15",
      "ticker": "MSFT",
      "tranType": "Buy",
      "qty": 36,
      "costPerShare": 149.03
      },
      {
      "acct": 101,
      "dateOfTrade": "2021-09-15",
      "ticker": "tsla",
      "tranType": "Buy",
      "qty": 4,
      "costPerShare": 755.83
      }
      ]
      }
      }
      },
      "slovakia": {
      "entityStockShares": {
      "label": "Common Stock, that is outstanding",
      "desc": "# of shares each customer holds",
      "units": {
      "trades": [
      {
      "acct": 6101,
      "dateOfTrade": "2021-09-15",
      "ticker": "DATG",
      "tranType": "Buy",
      "qty": 22,
      "costPerShare": 6.00
      },
      {
      "acct": 6101,
      "dateOfTrade": "2021-09-15",
      "ticker": "KRKG",
      "tranType": "Buy",
      "qty": 13,
      "costPerShare": 111.50
      },
      {
      "acct": 6101,
      "dateOfTrade": "2021-09-15",
      "ticker": "PETG",
      "tranType": "Buy",
      "qty": 41,
      "costPerShare": 442.00
      }
      ]
      }
      }
      },
      "ecuador": {
      "entityStockShares": {
      "label": "Common Stock, that is outstanding",
      "desc": "# of shares each customer holds",
      "units": {
      "trades": [
      {
      "acct": 12101,
      "dateOfTrade": "2021-09-15",
      "ticker": "Banco Pichincha",
      "tranType": "Buy",
      "qty": 22,
      "costPerShare": 80.00
      },
      {
      "acct": 12101,
      "dateOfTrade": "2021-09-15",
      "ticker": "BOLIVARIAN BANK",
      "tranType": "Buy",
      "qty": 22,
      "costPerShare": 0.84
      }
      ]
      }
      }
      },
      "mexico": {
      "entityStockShares": {
      "label": "Common Stock, that is outstanding",
      "desc": "# of shares each customer holds",
      "units": {
      "trades": [
      {
      "acct": 246101,
      "dateOfTrade": "2021-09-15",
      "ticker": "AGUA",
      "tranType": "Buy",
      "qty": 22,
      "costPerShare": 31.57
      }
      ]
      }
      }
      }
      }
      }

  • @MrZtapp
    @MrZtapp 2 года назад

    Exactly what I need, GREATE tutorial

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      Hey Peter, Glad to hear this video was helpful. Here is a video that may save you a lot of time creating C# classes:
      How to Tutorial to use Visual Studios to automatically Deserialize JSON into C# in just seconds.
      ruclips.net/video/5NOhai66okg/видео.html

  • @ionutcatalin525
    @ionutcatalin525 Год назад

    Thank you very much, very well explained!

    • @SoftwareNuggets
      @SoftwareNuggets  Год назад

      Appreciate you leaving a comment. I hope this video was useful.

    • @ionutcatalin525
      @ionutcatalin525 Год назад +1

      @@SoftwareNuggets Super helpful!!!
      Maybe you can make a complete tutorial with Linq and lambdas

    • @SoftwareNuggets
      @SoftwareNuggets  Год назад

      Did you check out the few I have?

    • @ionutcatalin525
      @ionutcatalin525 Год назад +1

      @@SoftwareNuggets No, I managed to understand Sql and I'm at the beginning with Linq and lambdas.
      I will watch the clips and come back with the feedback of a beginner

    • @SoftwareNuggets
      @SoftwareNuggets  Год назад

      Well, SQL is a great skill to have. I have many years of experience, and a lot of videos on this channel. I look forward to you viewing more videos and sharing your experience with me.

  • @sandy_git
    @sandy_git Год назад

    Thank you for the video, you explained so perfect. Can you do extension of this tutorial? how to use LINQ and access the data from complex JSON through LINQ I am struggling to filter the data from JSON after it's deserialized and iterate the nested arrays

    • @SoftwareNuggets
      @SoftwareNuggets  Год назад +1

      Thanks for leaving a comment. So, can you share with me your JSON, and I will create a video that uses your design. If you have private data, just replace with junk data. If you would like for me to do this: send your JSON to softwareNugget65@gmail.com.

  • @PaoloPechoIman1981
    @PaoloPechoIman1981 6 месяцев назад

    excelente video..

  • @riccarrasquilla379
    @riccarrasquilla379 11 месяцев назад

    thanks for the explanation

  • @frazd441
    @frazd441 2 года назад

    Many thanks for this video, explanation is superb!
    A question... How would you model it to allow null on any of these values?

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      In c# code make the field nullable
      Example: public int? MightBeUsed {get; set;}

    • @frazd441
      @frazd441 2 года назад +1

      @@SoftwareNuggets wow, thanks, sounds like somethink I should have known already 😁

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      it's all good. glad to help.

  • @SharaPk
    @SharaPk 3 года назад

    This Video is great ! Thank you a lot

    • @SoftwareNuggets
      @SoftwareNuggets  3 года назад

      Thank you Shara for viewing another video, I appreciate your support.

  • @melcushnahan618
    @melcushnahan618 Год назад

    Thanks this really helped

  • @notpumkin
    @notpumkin 2 года назад

    The [JsonProperty("propertyNameInJson")] attribute lets you change the name of the property in your class and still serialize/deserialize correctly.

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      Thank you for this comment, sounds like a good video to make to show people how it works. Thanks pumkin.

  • @Trunkss6
    @Trunkss6 2 года назад

    Hey awesome video man! Is there any chance you could show deserialization without console application but instead using Wpf App(.Net Framework)? Also I would love to see how you use CRUD operations and when you create something how you can store it in a JSON file.

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад +1

      Hey FrozeN, thanks for leaving the comment above. Thank you for the idea of creating a video to perform the CRUD operations and use a WPF app. I will begin that tonight, should have available by Saturday (April 16, 2022) or sooner.

    • @Trunkss6
      @Trunkss6 2 года назад

      Great excellent! Thank you,too bad i have some project for tommorow regarding those things😔.But i probably won't be able to do it myself, so i will make sure to check your video when you publish it!

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад +1

      @@Trunkss6 , well, let's speed this up. do you already have a screen, and object you wanna use.
      if your object is big, just skinny down for me, and I will make you a private video. I will send to an email address or something, we will figure that out later.
      1) send xaml for screen
      2) send class object you started working on
      3) you want to be able to insert,update and delete records from a serialized/deserialized json file, correct?
      4) send to softwarenugget65@gmail.com

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад +1

      Hey FrozeN, The video I promised you has been published. Enjoy.

    • @Trunkss6
      @Trunkss6 2 года назад

      @@SoftwareNuggets I will look it right away,thanks man :)

  • @doondisanapala9108
    @doondisanapala9108 2 года назад

    Can you Please answer this, how to write code in repository class joining all the classes that we created here

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      Hey Doondi, I don't understand what you are asking. Can you try again, be very clear, so I can understand and how to help you.
      I do have quite a few video on this topic. You should first watch all those videos, and perhaps question will get answered, OR, you will know exactly what to ask me for help. Don't skip around and go fast, commit some time and learn.
      Here is a link for the play list:
      ruclips.net/p/PLRU_t-SgTrYhb7xAgZ3ViPEw1L7dI6yHV

  • @deegeeooh
    @deegeeooh 3 года назад

    Great stuff! Your video's helped me understanding this better.
    Also, I recently found out you can paste JSON as a CLASS via 'Paste Special' in an empty class window (in Vstudio), really handy, no typing errors :)
    I also have a question: (probably a just a rookie syntax question ;D) So I've deserialised some JSON text into several list objects which are structured as their corresponding classes. How can I invoke methods passing a variable list type? So for instance:
    public static void DisplayRecord(List aList, int aRecordnumber)
    {
    // display stuff
    }
    How can I make the 'Employee' type in this method variable ?

    • @SoftwareNuggets
      @SoftwareNuggets  3 года назад

      hey deegeeooh; here is a small program I think will solve your question. if not, tell me more.
      inside of app, I sent you a link to another video I made, about INITIALiZING .... i think will help you in general.
      using System;
      using System.Collections.Generic;
      namespace Employee
      {
      class Program
      {
      static void Main(string[] args)
      {
      var all = new List();
      // watch this video
      // ruclips.net/video/NrZ9I0i27IA/видео.html
      Employee a = new Employee();
      a.FName = "deegeeooh";
      a.LName = "programmer";
      all.Add(a);
      Employee b = new Employee();
      b.FName = "scott";
      b.LName = "programmer2";
      all.Add(b);
      // if you are debugging, press F11 to step into this method
      PrintAllEmployees(all);
      }
      static void PrintAllEmployees(List all_the_employees)
      {
      foreach(var emp in all_the_employees)
      {
      Console.WriteLine("FirstName = " + emp.FName + ", LastName = '" + emp.LName);
      }
      }
      }
      public class Employee
      {
      public string FName { get; set; }
      public string LName { get; set; }
      }
      }

    • @deegeeooh
      @deegeeooh 3 года назад

      @@SoftwareNuggets Hi Mr. Nuggets, appreciate your elaborate answer, thanks! I watched your video too, very useful, love the debug tip. However, this I understand and use. I didn't explain my question very well, let me elaborate. Based on your example code, what I'm trying to achieve is generalizing the 'PrintAllEmployees' method so it can be called with Lists of any class type. But since it is a strongly typed list, I have to give it a dedicated type ('Employee' in your example) when I define the method. How can I make this method accept variable types of List ?
      So in pseudo code this would look like:
      static void PrintAllListMembers (List aListname)
      {
      }
      It's probably simple, but I haven't found the answer yet.
      Hope this clears up my question.
      Thanks again for your effort !

    • @SoftwareNuggets
      @SoftwareNuggets  3 года назад +1

      //hope this is what you are looking for
      using System;
      using System.Collections;
      using System.Collections.Generic;
      using System.Linq;
      namespace Employee
      {
      class Program
      {
      static void Main(string[] args)
      {
      var all = new List();
      // watch this video
      // ruclips.net/video/NrZ9I0i27IA/видео.html
      Employee a = new Employee();
      a.FName = "deegeeooh";
      a.LName = "programmer";
      all.Add(a);
      Employee b = new Employee();
      b.FName = "scott";
      b.LName = "programmer2";
      all.Add(b);
      // if you are debugging, press F11 to step into this method
      for (int i = 0; i < all.Count; i++)
      PrintEmployee(all[i].FName, all[i].LName);
      List boss = new();
      Owners boss1 = new Owners();
      boss1.xxxx = "deegeeooh";
      boss1.yyyy = "programmer";
      boss.Add(boss1);
      Owners b2 = new Owners();
      b2.xxxx = "scott";
      b2.yyyy = "programmer2";
      boss.Add(b2);
      for (int i = 0; i < boss.Count; i++)
      PrintEmployee(boss[i].xxxx, boss[i].yyyy);
      }
      static void PrintEmployee(T1 f1, T1 f2)
      {
      Console.WriteLine("firstName:" + f1 + ", lastName:" + f2);
      }
      }
      public class Owners
      {
      public string xxxx { get; set; }
      public string yyyy { get; set; }
      }
      public class Employee
      {
      public string FName { get; set; }
      public string LName { get; set; }
      }
      }

    • @SoftwareNuggets
      @SoftwareNuggets  3 года назад +1

      To Object to Print Line, we need to use an Interface (the columns we want to print must be the same)
      using System;
      using System.Collections;
      using System.Collections.Generic;
      using System.Linq;
      namespace Employee
      {
      class Program
      {
      static void Main(string[] args)
      {
      var all = new List();
      // watch this video
      // ruclips.net/video/NrZ9I0i27IA/видео.html
      var a = new ZEmployee();
      a.FName = "deegeeooh";
      a.LName = "programmer";
      all.Add(a);
      var b = new ZEmployee();
      b.FName = "scott";
      b.LName = "programmer2";
      all.Add(b);
      // if you are debugging, press F11 to step into this method
      for (int i = 0; i < all.Count; i++)
      PrintEmployee(all[i].FName, all[i].LName);
      List boss = new List();
      var boss1 = new ZOwners();
      boss1.FName = "deegeeooh";
      boss1.LName = "programmer";
      boss.Add(boss1);
      var b2 = new ZOwners();
      b2.FName = "scott";
      b2.LName = "programmer";
      boss.Add(b2);
      for (int i = 0; i < boss.Count; i++)
      PrintEmployee(boss[i].FName, boss[i].LName);
      PrintList(all);
      PrintList(boss);
      }
      static void PrintList(List people) where T : INamedPerson
      {
      foreach(var p in people)
      {
      Console.WriteLine(p.LName);
      }
      }
      static void PrintEmployee(T1 f1, T1 f2)
      {
      Console.WriteLine("firstName:" + f1 + ", lastName:" + f2);
      }
      }
      public class ZOwners: INamedPerson
      {
      public string FName { get; set; }
      public string LName { get; set; }
      public int Age { get; set; }
      public int Rate { get; set; }
      }
      public class ZEmployee: INamedPerson
      {
      public string FName { get; set; }
      public string LName { get; set; }
      public Decimal Salary { get; set; }
      public int YearsOnStaff { get; set; }
      }
      public interface INamedPerson
      {
      string FName { get; set; }
      string LName { get; set; }
      }
      }

    • @deegeeooh
      @deegeeooh 3 года назад +1

      @@SoftwareNuggets Somehow I didn't get a notification of YT of your answer, I'm just reading this. Thanks, very much appreciated, I'm going to check this out to see if I can wrap my head around this :)

  • @essamce1436
    @essamce1436 2 года назад

    Do you think you could have added one class called "country" instead of "worldInvestor" and in this case "_accounts" will only have one property under it called "List countries"

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      Hey Essam, this is a good question.
      so,
      "USA","SLOVAKIA", "ECUADOR",""MEXICO" are objects.
      that is why I had to create "worldInvestor",
      for each "instance" of "worldInvestor", I had to "NAME" "usa","slovakia","ecuador","mexico", so NewtonSoft could MAP those object correctly.
      this doesn't mean, the way I think is correct, It's just a pattern I use to solve these type of JSON problems. I try to keep it as simple as POSSIBLE every single time.

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      Hey Essam, I just put out another video about JSON Deserialization. I think if you watch this video, it will give you some ideas.
      Ex3: Step-by-Step, I will show you the steps it takes to build C# class objects to DESERIALIZE JSON.
      ruclips.net/video/Qp4f6ZJKciE/видео.html
      1) Build class object C#
      2) Serialize (c# -> JSON)
      3) So, try out the worldInvestor problem with your class object design, then serialize
      4) Let me know your results.
      5) hope this helps

  • @patyue5012
    @patyue5012 Год назад

    However, when you come to get 3rd party API, it is a different story. I have difficult to show the response as c# classes.

    • @SoftwareNuggets
      @SoftwareNuggets  Год назад +1

      Can you send the json to softwarenugget65@gmail.com, and I will take a look

  • @arinoksas
    @arinoksas 2 года назад

    In example 4; What if there was more than 4 countries? For example there is 1500 countries, we should add one by one like this? How we can generate it automatically?

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      Hey Arin, plz don't do one-by-one. First question, is the JSON valid? Second Question: do you understand key, value. in example #4, the countries (are the key, and the value are big objects), so, this is not the format you want.
      Are you the person that designed the JSON?
      Can you send me the JSON?
      softwareNugget65@gmail.com
      Do you have visual studios?
      Please watch this video, it may help you:
      How to Tutorial to use Visual Studios to automatically Deserialize JSON into C# in just seconds.
      ruclips.net/video/5NOhai66okg/видео.html
      I created this video in Jan 2022.

  • @thebulletkin8393
    @thebulletkin8393 2 года назад

    I’m writing a program where a new object is created and added to a list every time I click, then saved when another button is clicked. If I create a list of those objects can I then do a similar thing here and mash them all into one big json file?
    To be more specific, it’s a school project where I’m making a golf app. Every time I click I need to store information about each shot (the surface type, the coordinates etc). But when I want to save it I want there to be “hole” : 1 followed by the list of shots as objects, then “strokes” : 5 for example. Is that possible?

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      Serialize object and your done.

    • @thebulletkin8393
      @thebulletkin8393 2 года назад

      @@SoftwareNuggets I’ll see what I can do, I’m still fairly new to c#
      Another question if you don’t mind, what does Get set and that notation it’s surrounded in do?

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      Those allow you to give and get a value from that field. Say you wanted a read only field, you would only apply the get

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      www.w3schools.com/cs/cs_properties.php

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      Did that link about Get and Set make sense?

  • @nickbarton3191
    @nickbarton3191 Месяц назад

    And why doesn't it support BSON out of the box?

    • @SoftwareNuggets
      @SoftwareNuggets  Месяц назад

      Newtonsoft json must be installed. That’s what I meant. Sorry for the confusion.

  • @jakubwodarczyk2359
    @jakubwodarczyk2359 2 года назад

    But how can I deserialize json that looks like this [ {} ]

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      static void Main(string[] args)
      {
      string filename = @"c:\temp\youtube\customer.json";
      // let's build a C# class object
      var dyn_obj = BuildDynamicObj();
      // let's convert c# class object to a "json" object
      var json = Newtonsoft.Json.JsonConvert.SerializeObject(dyn_obj);
      if (System.IO.File.Exists(filename) == false)
      {
      System.IO.File.WriteAllText(filename, json);
      }
      else
      {
      System.IO.File.Delete(filename);
      System.IO.File.WriteAllText(filename, json);
      }
      var data = JsonConvert.DeserializeObject(json);
      }
      private static List BuildDynamicObj()
      {
      var a = new List
      {
      new { }
      };
      return (a);
      }

  • @sundarraaj2944
    @sundarraaj2944 2 года назад

    How to serialise complex nested c# class object into json object

    • @SoftwareNuggets
      @SoftwareNuggets  2 года назад

      Have you seen this video I created?
      How to Serialize / Deserialize JSON Object using C# and Newtonsoft Json. (4:56)
      ruclips.net/video/L0dxU47TzYY/видео.html

  • @robsoncardoso8692
    @robsoncardoso8692 9 месяцев назад

    How to generate XML from this file and save it in the folder?

    • @SoftwareNuggets
      @SoftwareNuggets  9 месяцев назад +1

      Hey @robsoncardoso8692, so you have a file that is formatted in json, and you want to convert it to xml?

    • @SoftwareNuggets
      @SoftwareNuggets  9 месяцев назад

      I found this on the internet, it untested :
      string json = @"{
      '@Id': 1,
      'Email': 'james@example.com',
      'Active': true,
      'CreatedDate': '2013-01-20T00:00:00Z',
      'Roles': [
      'User',
      'Admin'
      ],
      'Team': {
      '@Id': 2,
      'Name': 'Software Developers',
      'Description': 'Creators of fine software products and services.'
      }
      }";
      XNode node = JsonConvert.DeserializeXNode(json, "Root");
      Console.WriteLine(node.ToString());

    • @robsoncardoso8692
      @robsoncardoso8692 8 месяцев назад

      @@SoftwareNuggets yes, i have this file:
      {
      "ide": {
      "nf": {
      "cUF": 42,
      "cNF": 43617
      }
      }
      }

    • @SoftwareNuggets
      @SoftwareNuggets  8 месяцев назад

      Did you try the command I provided in my previous comment?