Тёмный

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

dotnet
Подписаться 302 тыс.
Просмотров 13 тыс.
50% 1

Опубликовано:

 

3 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 30   
@catalystcorp
@catalystcorp 9 месяцев назад
I will forever pronounce it Jason and I will die on this hill!
@dand4485
@dand4485 7 месяцев назад
Hahah it all matters how you say "data", or is coke, soda, pop.... Hahah... 🤪
@LahceneBelbachir
@LahceneBelbachir 4 месяца назад
Same here, and since even Douglas Crockford himself always called it Jason, I think we're good.
@kylewatson5133
@kylewatson5133 9 месяцев назад
Json serialization of c# classes is incredibly powerful....
@pbible
@pbible 8 месяцев назад
James Rocks!!
@nuthanmurari
@nuthanmurari 8 месяцев назад
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.
@rusektor
@rusektor 9 месяцев назад
17:42 Instead of using some dummy statement, you could equally use empty statement with one semicolon in the beginning of the line. 😉
@vencislavvidov
@vencislavvidov 9 месяцев назад
What about deserialize complex object containing List or Dictionary of others complex nested objects? For example an Invoice:)
@ryfatron3963
@ryfatron3963 9 месяцев назад
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?
@phizc
@phizc 9 месяцев назад
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 8 месяцев назад
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.
@leppyr64
@leppyr64 7 месяцев назад
Love the comedy of how hard you're trying say JSON and not Jason.
@alfflasymphonyx
@alfflasymphonyx 9 месяцев назад
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 9 месяцев назад
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 9 месяцев назад
@@JamesMontemagnoCorrect. I guess a function DeserializeFromFile would do
@RamonDeKlein
@RamonDeKlein 9 месяцев назад
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 9 месяцев назад
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
@enriquebenedicto9429
@enriquebenedicto9429 9 месяцев назад
Not sure I understand why it needed to be Async
@RamonDeKlein
@RamonDeKlein 9 месяцев назад
File or network I/O may block, so async may be useful if scalability is important.
@enriquebenedicto9429
@enriquebenedicto9429 9 месяцев назад
@@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 9 месяцев назад
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.
@vivekkaushik9508
@vivekkaushik9508 9 месяцев назад
Why did James loose his long curly hair?
@JamesMontemagno
@JamesMontemagno 9 месяцев назад
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 9 месяцев назад
so thoughtful of you @@JamesMontemagno
@ibrahimhussain3248
@ibrahimhussain3248 9 месяцев назад
Where's James Newton King?
@JamesMontemagno
@JamesMontemagno 9 месяцев назад
Working on the ASP.NET Core team twitter.com/JamesNK
@acidhauss7018
@acidhauss7018 9 месяцев назад
Newtonsoft - i.e. if it aint broke dont fix it!
Далее