-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Trying to convert JSON to Object using Newtonsoft freezes #16001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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. |
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) ! |
@danroth27 |
@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 |
@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?
The text was updated successfully, but these errors were encountered: