Hey Royur, Spending hours looking for the right video, I've been there too. I was very happy to read, this video was really helpful. I'd also like to thank you for leaving a message and subscribing to my channel. Thanks for the support. You might want to check out, "Use Visual Studios to generate C# class object to DESERIALIZE JSON", this video may speed up your development time when Deserializing JSON to C#. Thanks again.
UGH, I was trying to use a List instead of an Array to deserialize thank you for clearing this up for me without having to watch an hour long video : )
Hey Jason, Thanks for leaving a message and subscribing to my channel, I truly appreciate that. And very happy to hear, this video was able to shed some light on JSON arrays. I hope after watching this video, you were able to solve your issue. A couple of days ago, I released, "Use Visual Studios to generate C# class object to DESERIALIZE JSON", this video may speed up your development time when deserializing JSON to C#. It's a 4 minute video, but, I think you can get the jiff in 30 seconds or less. Thanks again, and have a great week.
Awesome video. I have been searching a lot for an explanation this good. But how do I get out the values from eg. brand? Like I want to know what brands there are in the file?
Hey @donmanuello, I think this video I created will help you ruclips.net/video/FLI_dzxdjDQ/видео.html After you watch this, and you still don’t have an answer, I’m going to continue helping you. We are going to understand this code, I promise. So, watch this video first, then reach back out.
Hey Faqruddin, thanks for viewing this video, as for your question, can you share a little more? You want to know how to use the [for, foreach] and loop the C# array elements?
@@SoftwareNuggets yes. Assume Base class Name is ClaasBase and it has Salesid and Sales Name as normal objects and List is a list. So when I iterate the records first I want to refere base class i.e ClassBase and this class refere to List. How can I apply for or foreach so I can print SalesId, SalesName as normal values and SalesLines as list. Thank you.
Hey Faqruddin, I have an example in one of my other videos, to "foreach" loop over the object Step-by-Step how to Deserialize JSON Two Dimensional Array using C# Newtonsoft Top video. ruclips.net/video/FLI_dzxdjDQ/видео.html if you move to around 7:50, it starts to show you how to loop over. Let me know if this helps.
Good afternoon. great video! could you also provide the json file so I can simulate if it works on my end. thank you so much. I was looking at the "?" you use for null data, but is there a workaround for version .net framework 4.7.2? cause this has been introduced for later version.
Can you please send me your program where nullable doesn't work. Include the project/solution, just zip up all that project, and send to me, if you'd like for me to look at it. Send to: softwareNugget65@gmail.com
Hey Margarida Lopes, thanks for viewing the video and kind comment. Not sure exactly what you mean "access the properties" , but I will guess: Only have items in your C# class you want to extract from your JSON. here is an example: public class _model { public string model { get; set; } //public int? basePrice { get; set; } public string[] colors { get; set; } } noticed I commented out base_price. now, base_price is no longer in your c# class object, it was skipped from your json data. If I didn't answer your question, please try again with a different questions, with more details, and I am sure we will get it in the end.
Hey avidity2002. Yes, you can use a list. This video will show you how. ruclips.net/video/lLMIvOd3lhk/видео.html please let me know if this solved your JSON problem.
Sir, I have this code to extract json file. I have done same according to you. When I build project, it doesn't show any error but it doesn't show extracted values of feilds in the "data" field as you have shown through pointer. Please solve this. static void Main(string[] args) {
string fileName = @"C:\prize.json"; string jsonText = File.ReadAllText(fileName); var data = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonText); Console.ReadLine(); } public class Rootobject { public Prize[] prizes { get; set; } } public class Prize { public string year { get; set; } public string category { get; set; } public Laureate[] laureates { get; set; } public string overallMotivation { get; set; } } public class Laureate { public string id { get; set; } public string firstname { get; set; } public string surname { get; set; } public string motivation { get; set; } public string share { get; set; } }
I hear you. C# is a typed language, so, that's why. Did you see my video on Dynamic JSON. If your JSON isn't to complicated, that might work. ruclips.net/video/nuifiGsgGA0/видео.html Good luck mate.
I just created you a new video, to generate C# with NO Coding. take a look if you are still interested. if you have time, please let me know if this video helped. Use Visual Studios to generate C# class object to DESERIALIZE JSON ruclips.net/video/5NOhai66okg/видео.html
C# code for project
/***************** main.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:\tmp\arrays.json";
string jsonText = File.ReadAllText(fileName);
var data = Newtonsoft.Json.
JsonConvert.DeserializeObject(jsonText);
}
}
}
/*************** whip.cs *********************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ModelThatJSON
{
public class Whip
{
public vehicle[] cars { get; set; }
public vehicle[] trucks { get; set; }
}
public class vehicle
{
public string brand { get; set; }
public _model[] models { get; set; }
}
public class _model
{
public string model { get; set; }
public int? basePrice { get; set; }
public string[] colors { get; set; }
}
}
/***********
{
"cars": [
{
"brand": "Toyo",
"models": [
{
"model": "car_model_1",
"basePrice": 18000,
"colors":
[
"red",
"white",
"blue"
]
},
{
"model": "car_model_2",
"colors":
[
"red",
"white",
"blue",
"gray",
"sky"
]
},
{
"model": "car_model_3",
"colors":
[
"red",
"white",
"blue",
"green"
]
}
]
},
{
"brand": "Hoyo",
"models": [
{
"model": "car_model_hoy_1",
"basePrice": 18000,
"colors":
[
"red",
"white",
"blue"
]
},
{
"model": "car_model_hoy_2",
"colors":
[
"red",
"white",
"blue",
"yellow",
"orange"
]
},
{
"model": "car_model_hoy_3",
"basePrice": 32000,
"colors":
[
"red",
"white",
"blue",
"orange",
"brown",
"yellow",
"purple"
]
},
{
"model": "car_model_hoy_4",
"basePrice": 34500,
"colors":
[
"red",
"white",
"blue",
"orange",
"brown"
]
},
{
"model": "car_model_hoy_5",
"basePrice": 37000,
"colors":
[
"red",
"white",
"blue",
"orange",
"brown"
]
},
{
"model": "car_model_hoy_6",
"basePrice": 54000,
"colors":
[
"blue",
"orange",
"brown",
"white"
]
}
]
}
],
"trucks": [
{
"brand": "Toyo",
"models": [
{
"model": "truck_model_1",
"basePrice": 18000,
"colors": [
"red",
"white",
"blue"
]
},
{
"model": "truck_model_2",
"colors": [
"red",
"white",
"blue",
"gray",
"sky"
]
},
{
"model": "truck_model_3",
"colors": [
"red",
"white",
"blue",
"green"
]
}
]
},
{
"brand": "Hoyo",
"models": [
{
"model": "truck_model_hoy_1",
"basePrice": 18000,
"colors": [
"red",
"white",
"blue"
]
},
{
"model": "truck_model_hoy_2",
"colors": [
"red",
"white",
"blue",
"yellow",
"orange"
]
},
{
"model": "truck_model_hoy_3",
"basePrice": 32000,
"colors": [
"red",
"white",
"blue",
"orange",
"brown",
"yellow",
"purple"
]
},
{
"model": "truck_model_hoy_4",
"basePrice": 34500,
"colors": [
"red",
"white",
"blue",
"orange",
"brown"
]
},
{
"model": "truck_model_hoy_5",
"basePrice": 37000,
"colors": [
"red",
"white",
"blue",
"orange",
"brown"
]
},
{
"model": "truck_model_hoy_6",
"basePrice": 54000,
"colors": [
"blue",
"orange",
"brown",
"white"
]
}
]
}
]
}
I have been going through hours of content trying to work this out. You are the only person that made it make sense. Thank you very much!
Hey @Mumbolian, appreciate you leaving this message. Wish you much success. -Scott
Thank you for you quick response. My model is deeper and more complicated, but this gives me a starting point.
You're welcome!
Thank you for this video. Been looking for hours on how to do this. Its really helpful.
Hey Royur,
Spending hours looking for the right video, I've been there too. I was very happy to read, this video was really helpful. I'd also like to thank you for leaving a message and subscribing to my channel. Thanks for the support.
You might want to check out, "Use Visual Studios to generate C# class object to DESERIALIZE JSON", this video may speed up your development time when Deserializing JSON to C#.
Thanks again.
UGH, I was trying to use a List instead of an Array to deserialize thank you for clearing this up for me without having to watch an hour long video : )
Hey Jason,
Thanks for leaving a message and subscribing to my channel, I truly appreciate that. And very happy to hear,
this video was able to shed some light on JSON arrays. I hope after watching this video, you were able to solve your issue.
A couple of days ago, I released, "Use Visual Studios to generate C# class object to DESERIALIZE JSON", this video may speed up your development time when deserializing JSON to C#. It's a 4 minute video, but, I think you can get the jiff in 30 seconds or less.
Thanks again, and have a great week.
thanks for the video man !
I hope this video was useful. thanks for leaving a comment @ahmadjerjees428
Thank you so much for explaining things so clearly, It helped me a lot. Thank you.
Hey x3InThp!, glad to hear this video was useful. Thanks for leaving me a comment.
Awesome video. I have been searching a lot for an explanation this good. But how do I get out the values from eg. brand? Like I want to know what brands there are in the file?
Hey @donmanuello, I think this video I created will help you
ruclips.net/video/FLI_dzxdjDQ/видео.html
After you watch this, and you still don’t have an answer, I’m going to continue helping you. We are going to understand this code, I promise.
So, watch this video first, then reach back out.
@@SoftwareNuggets Thank you so much. That helped a lot. I'm going to watch more of your videos. You're awesome
Thanks for the feedback. After you finish reviewing, and you need some help, just give me a shout.
Life saver!!!!!!!!!!!!!!!!!!!!!!!
Glad to hear this video was a life saver.
Thank you. Simple and easy to understand
Hey Sri Varanasi,
Thanks for taking the time to leave a comment, much appreciated. Glad to hear this video was useful.
Perfect! Thanks for a great video.
Hey Jim Grant,
Saying "Perfect" is a huge compliment. Thank you very much.
great explanation, thanks for the video
Glad it was helpful! If you need any other assistance, please let me know. Thanks again.
It would be great if you could also supply the source json and c# code. Thanks
Hey abbot, I just pushed software as first comment, which is pinned.
master, when we try to deserialize a complex json with a dinamic of names and colums do u have any exxample ?
Did you see my video on Deserialize JSON to Dynamic C#?
ruclips.net/video/nuifiGsgGA0/видео.html
@@SoftwareNuggets thk u
This helped a lot! One question I have is what if there was just one car array and 'cars' was not there in the response? How would the modeling be?
Can you send me a sample json file to softwareNugget65@gmail.com and I will model for you.
@@SoftwareNuggets wow thanks! Sent.
Check your email
Thank you. How can I make for and for-each models element only.
Hey Faqruddin, thanks for viewing this video, as for your question, can you share a little more? You want to know how to use the [for, foreach] and loop the C# array elements?
@@SoftwareNuggets yes. Assume Base class Name is ClaasBase and it has Salesid and Sales Name as normal objects and List is a list. So when I iterate the records first I want to refere base class i.e ClassBase and this class refere to List. How can I apply for or foreach so I can print SalesId, SalesName as normal values and SalesLines as list. Thank you.
Can u send me the json sample data. SoftwareNugget65@gmail.com
Hey Faqruddin, I have an example in one of my other videos, to "foreach" loop over the object
Step-by-Step how to Deserialize JSON Two Dimensional Array using C# Newtonsoft Top video.
ruclips.net/video/FLI_dzxdjDQ/видео.html
if you move to around 7:50, it starts to show you how to loop over.
Let me know if this helps.
@@SoftwareNuggets Thank you for sharing. Please kindly check your email with subject Json For/Foreach Lists
Good afternoon. great video! could you also provide the json file so I can simulate if it works on my end. thank you so much. I was looking at the "?" you use for null data, but is there a workaround for version .net framework 4.7.2? cause this has been introduced for later version.
disregard. I saw that you posted in earlier comment. thanks!
Can you please send me your program where nullable doesn't work. Include the project/solution, just zip up all that project, and send to me, if you'd like for me to look at it.
Send to: softwareNugget65@gmail.com
Hey!
first of all, great video!
How do we access the properties that we want?
Hey Margarida Lopes, thanks for viewing the video and kind comment.
Not sure exactly what you mean "access the properties" , but I will guess:
Only have items in your C# class you want to extract from your JSON.
here is an example:
public class _model
{
public string model { get; set; }
//public int? basePrice { get; set; }
public string[] colors { get; set; }
}
noticed I commented out base_price.
now, base_price is no longer in your c# class object, it was skipped from your json data.
If I didn't answer your question, please try again with a different questions, with more details, and I am sure we will get it in the end.
@@SoftwareNuggets Hello once again!
Yes, it answered my question!
Thank you very much!
You just saved me a lot of hours ahahah
keep up the good work!
Hi, could it be possible to deserialize nested dictionaries instead of an array?
Can you send me some sample json? Send to softwarenugget65@gmail.com
I need some help reading a nested Json. Can we not use List?
Hey avidity2002.
Yes, you can use a list. This video will show you how.
ruclips.net/video/lLMIvOd3lhk/видео.html
please let me know if this solved your JSON problem.
Advidity2002 - i just sent you two emails that will solve your issue.
Sir, I have this code to extract json file. I have done same according to you. When I build project, it doesn't show any error but it doesn't show extracted values of feilds in the "data" field as you have shown through pointer. Please solve this.
static void Main(string[] args)
{
string fileName = @"C:\prize.json";
string jsonText = File.ReadAllText(fileName);
var data = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonText);
Console.ReadLine();
}
public class Rootobject
{
public Prize[] prizes { get; set; }
}
public class Prize
{
public string year { get; set; }
public string category { get; set; }
public Laureate[] laureates { get; set; }
public string overallMotivation { get; set; }
}
public class Laureate
{
public string id { get; set; }
public string firstname { get; set; }
public string surname { get; set; }
public string motivation { get; set; }
public string share { get; set; }
}
can you send me the json file. softwareNugget65@gmail.com
{
"year": "2022",
"category": "programming",
"laureates": [
{
"id": "1",
"firstname": "one",
"surname": "lastone",
"motivation": "self",
"share": "always"
},
{
"id": "2",
"firstname": "two",
"surname": "lasttwo",
"motivation": "self",
"share": "always"
}
],
"overallmotivation": "highly motivated"
}
using System;
namespace MyApp // Note: actual namespace depends on the project name.
{
internal class Program
{
static void Main(string[] args)
{
string fileName = @"C:\dev\prize.json";
string jsonText = File.ReadAllText(fileName);
var data = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonText);
Console.ReadLine();
}
public class Rootobject
{
public string year { get; set; }
public string category { get; set; }
public Laureate[] laureates { get; set; }
public string overallMotivation { get; set; }
}
public class Laureate
{
public string id { get; set; }
public string firstname { get; set; }
public string surname { get; set; }
public string motivation { get; set; }
public string share { get; set; }
}
}
}
Hi can you help me ?
How can I help you?
Why does unity have to make JSON this difficult. It's json, why not just JSON.Parse and be done with it?
I hear you. C# is a typed language, so, that's why. Did you see my video on Dynamic JSON. If your JSON isn't to complicated, that might work.
ruclips.net/video/nuifiGsgGA0/видео.html
Good luck mate.
I just created you a new video, to generate C# with NO Coding. take a look if you are still interested.
if you have time, please let me know if this video helped.
Use Visual Studios to generate C# class object to DESERIALIZE JSON
ruclips.net/video/5NOhai66okg/видео.html
Hi can you help ?
Hey @@kristelfernandez6717, how can I help you?