Thank you for this video, this really helped me. I'm just starting out in C# and I'm sure what I was trying to do could be done a lot better, but this was the easiest for me to understand!
First of all: fantastic gem! Subscribed to the channel! Then, the question (maybe it's already answered in another video, so in the case could you point it out?): I'm playing around with json and encountered a problem. In short: I have a json like this stored in a database table {"fields":[{"field1":"value1"},{"field2":"value2"},etc.etc.]}, where the name and number of fields could change between rows. So i could have the field2 but not the field1, or field34, and maybe field20 repeated 2 or more times. The question is: how should look a class representing this kind of data? I tested many ways (list of keyvaluepair for example, or list of another class defining the single field-value couple) but always get some trouble while deserializing and also while querying with tsql on sql server (json_value, json_query, etc. don't seems to support for iteration on the elements of the array...). So I'm a bit stuck on that... could you give me some advise or give any direction to look to? Thanks in advance for any suggestion and again: amazing video! Thank you for that!
This is a great video and very clear, but I would like to see how you handle this case but with multiple strings of the same format you've shown here. Do you have to create multiple lists? Or can you do it with a list of lists (e.g. nested)?
Very useful, thanks - the only thing I would add is that I had access denied when trying to read in from a file (even when running VS 2022 as Administrator). Any tips on sorting that would be great (I'm on a work computer so it's hard to know what else might be going on in the background)
How to deserialize this Json, what to do with the word "producto" before the properties? { "producto": { "iDpRODUCTO": 6, "codigoBarra": 54323, "nombre": "cera", "marca": "avon", "categoria": "belleza", "precio": 3400 } }
Ran into this early morning, helped me a bunch. Kinda stuck now, what do you do when you have "location": null? When I deserialize and try to read root.data.location, I get a System.NullReferenceException: 'Object reference not set to an instance of an object.' Document_Parser.readjson.Data.dateOfBirth.get returned null. Thanks
@@tuomaslehtonen1707 i cant find it under Tools. I have one in Visual studio -> Preference -> Text editor -> IntelliSense. It’s enable but not working like shown in your video. Didn’t saw anything related to C# in above path although I’m working with Unity & C#. Maybe a module is missing? 🤔
My dear Hobbyist programmer ... you should really put your DTOs in a common or Shared Project and not straight in your Console Application So you can have it referenced by other server or clients without having to export your console to your clients or servers you talk to and hence avoid circular references of your executable ... It's lovelty to see you just realized you could seriallize and deserialize Json .. well it;s not just Json .. it's Xml it's Objects and basically anything you can tuirn to a series of bytes and also strings ... (which are bytes anyway...lol) ... congratulations you discovered the oldest web Api practice just yesterday.. I guess better late than never ...welcome to reality man ... lol bye bye
using ConsoleApp1; using System.Text.Json; var person = new Person("Kevin", 19); var _serializeJSON = JsonSerializer.Serialize(person); File.WriteAllText("file.json", _serializeJSON); var readJSON = File.ReadAllText("file.json"); Person _deserialize = JsonSerializer.Deserialize(readJSON); Console.WriteLine($"{_deserialize.Name} is {_deserialize.Age} years old."); Console.ReadKey();