Closed tessierp closed 4 years ago
Yes, there is a known issue with using Json.NET with Blazor right now that we think will be addressed once we update to the latest mono.wasm support for our 0.4.0 release (#831).
Also, we have done work for 0.4.0 that will make the default JSON handling in Blazor be more flexible with casing on deserialization.
@tessierp You may take a try to my Json.NET.Aot package.
The only drawback, i found that it is slow when used with asmjs on low end devices. On WebAssembly it run smoothly IMO.
Turns out the issues we've had with Json.NET are with our linker configuration. If you want to use Json.NET in a Blazor app you can get it to work by using the following linker configuration: https://gist.github.com/Suchiman/a5e65f40c353120c9cf7f6a631ded28b.
Thanks a lot @danroth27 (and @Suchiman for the Gist) ! I will take a look on it Monday.
@danroth27 i have same issue , i just don`t know how to use that "linker" !? i don't have any linker in my Blazor project 0.4.0 please help
@moataz1991 The linker is run automatically as part of the build of a Blazor project. You can configure what the linker does to your app and get Json.NET to work by updating your .csproj file as shown in https://gist.github.com/Suchiman/a5e65f40c353120c9cf7f6a631ded28b.
@danroth27 ok now i got it , but to which .csproj do i modify and linker.xml to that project ? Server,Client or Shared ?
@moataz1991 Client, you want to modify the blazor app itself, not the app that just serves the static files.
Hi,
I've been trying to use Newtonsoft to convert a json string to an my expected model but each time I include Newtonsoft in a view and use it, it freezes. For example lets say I have a view with the following : ` @functions {
} ` I will get no output, nothing will happen. I tested this code including JsonConvert.DeserializeObject from Newtonsoft and the same thing happens.
I tested this outside of Blazor and it works fine.
Now you may wonder, why would I be doing this if I can call GetJsonAsync directly from Http? Well, initially the API I coded didn't have
services.AddMvc().AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver(); });
so all the json data started with a lowercase and it wouldn't resolve to my models which have properties starting with a Upper case for the first letter (this is probably a problem wit the HttpClient).
Anyways, anyways else has this problem with Blazor using NewtonSoft?