Welcome to System.Text.Json - How to read & write .NET objects as JSON

  Рет қаралды 14,098

dotnet

dotnet

Күн бұрын

Пікірлер: 30
@catalystcorp
@catalystcorp 11 ай бұрын
I will forever pronounce it Jason and I will die on this hill!
@dand4485
@dand4485 9 ай бұрын
Hahah it all matters how you say "data", or is coke, soda, pop.... Hahah... 🤪
@LahceneBelbachir
@LahceneBelbachir 7 ай бұрын
Same here, and since even Douglas Crockford himself always called it Jason, I think we're good.
@kylewatson5133
@kylewatson5133 11 ай бұрын
Json serialization of c# classes is incredibly powerful....
@ryfatron3963
@ryfatron3963 11 ай бұрын
Can we take the json file to deserialize into sth, Object, but we don't have that Class Template at first? Can we generate that Class along the Deserialization?
@nuthanmurari
@nuthanmurari 10 ай бұрын
I am happy to see this .NET works really hard in system.Text.Json in a wider way to use it. Advantage here is : No need of external library called Newtonsoft.Json Cons: How confident we are with System.Text.Json. Whether we good to go on usage with our inbuilt library? Please let us know everyone on this and from which .net version and c# language it supports all the functionality of NewtonSoft.Json in our inbuilt library. If you give that confidence to all dotnet programmers or architects we are really happy to use it with replacement of matured Newtonsoft.Json.
@vencislavvidov
@vencislavvidov 11 ай бұрын
What about deserialize complex object containing List or Dictionary of others complex nested objects? For example an Invoice:)
@rusektor
@rusektor 11 ай бұрын
17:42 Instead of using some dummy statement, you could equally use empty statement with one semicolon in the beginning of the line. 😉
@phizc
@phizc 11 ай бұрын
17:18 The reason it didn't hit the breakpoint is that it hit a breakpoint at the setter of the `Date` property on the WeatherForecast class. VS Code probably got confused by the breakpoint on the empty line. You just terminated the program too soon. The code was perfectly fine. `Deserialize` isn't an async method, so you didn't need the `await`. So the only "shocking" thing is that you used *non-async* file IO. Shudder /s. My best guess is that since the breakpoint was at the empty line 16, it moved the breakpoint to the first line that could have a breakpoint, which was the property at line 19. Stupid that VS Code would allow breakpoints on empty lines in the first place.
@dotnet
@dotnet 11 ай бұрын
Yup, @JamesMontemagno commented to a few others and we added this small correction in the video details: Correction: 00:17:18 Async isn't actually required here, the breakpoint didn't hit due to the program executing too soon and adding the Console.WriteLine would have fixed this up, although with File IO access async operations should be considered.
@alfflasymphonyx
@alfflasymphonyx 11 ай бұрын
And @16:58, similarly, just pass the filename to Deserialize instead of a FileStream. The FileStream should be used internally. I should not need to provide it.
@JamesMontemagno
@JamesMontemagno 11 ай бұрын
I don't think you an d just pass in the file name, if you pass in just a string it will try to deserialize that string: learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializer.deserialize?view=net-8.0
@alfflasymphonyx
@alfflasymphonyx 11 ай бұрын
@@JamesMontemagnoCorrect. I guess a function DeserializeFromFile would do
@pbible
@pbible 11 ай бұрын
James Rocks!!
@enriquebenedicto9429
@enriquebenedicto9429 11 ай бұрын
Not sure I understand why it needed to be Async
@RamonDeKlein
@RamonDeKlein 11 ай бұрын
File or network I/O may block, so async may be useful if scalability is important.
@enriquebenedicto9429
@enriquebenedicto9429 11 ай бұрын
@@RamonDeKlein yeah. I understand that. What I don't understand is that he implied it hadn't worked on the first try, because he hadn't used async. I can't imagine that being the case. But maybe I just missed some other comments he made.
@JamesMontemagno
@JamesMontemagno 11 ай бұрын
It would work either way. The main issue I ran into and couldn't' fix in edit was that I didn't have anything to break on after. So once I added the Console.WriteLine the breakpoint would have been hit. Although I would suggest async/await when handling this as it could be a very large JSON blob.
@leppyr64
@leppyr64 10 ай бұрын
Love the comedy of how hard you're trying say JSON and not Jason.
@RamonDeKlein
@RamonDeKlein 11 ай бұрын
Why dispose it manually? Use “await using” instead. Disposing it twice doesn’t make it more safe, just more complex, so it’s bad.
@JamesMontemagno
@JamesMontemagno 11 ай бұрын
Just me following docs :), but yes an await using would also work. the using will just call Dispose, but not DisposeAsync. I made a PR: github.com/dotnet/docs/pull/38948
@vivekkaushik9508
@vivekkaushik9508 11 ай бұрын
Why did James loose his long curly hair?
@JamesMontemagno
@JamesMontemagno 11 ай бұрын
I was heading out on holiday and knew i was going to do a lot of swimming so decided it was time. It was 12" total and I donated it to a charity where they make wigs for kids and cancer patients.
@VictorPraizTech
@VictorPraizTech 11 ай бұрын
so thoughtful of you @@JamesMontemagno
@ibrahimhussain3248
@ibrahimhussain3248 11 ай бұрын
Where's James Newton King?
@JamesMontemagno
@JamesMontemagno 11 ай бұрын
Working on the ASP.NET Core team twitter.com/JamesNK
@acidhauss7018
@acidhauss7018 11 ай бұрын
Newtonsoft - i.e. if it aint broke dont fix it!
Ignoring Properties when reading & writing JSON
14:42
dotnet
Рет қаралды 4,2 М.
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
Active Trader Pro Beta macOS Startup Timing
4:57
Michael Moy
Рет қаралды 118
Why is the UK denying treatment to children from Gaza? | Inside Story
28:56
Al Jazeera English
Рет қаралды 42 М.
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН