JsonConvert.SerializeObject always returns {} in XamarinForms

JsonConvert.SerializeObject does not seem to work on xamarin forms. Or I might be missing something here. Here is the result when I serialize a simple object. enter image description here

See how it returns {}. I also tried serializing the class and it returned the same.

What could be the problem?

UPDATE

There is still no solution to this problem. I tried to create a simple console application and serializeObject is working on this project, so I assume that it does not work only in xamarin formats. Does anyone have a xamarin creation project that runs serializedobject JSON.NET?

I am using visual studio 2017, json.net 10.0.3 and live player.

+3
source share
3 answers

I tried to configure the emulator on a fast machine, and it serializes the work! Thus, this means that it does not work when I launch it on a live player using my Android phone. For now, I will call it the answer. if someone else sent a message on how to make it work for a live player, I will set it as the correct answer

+1
source

This is a known issue, see https://developer.xamarin.com/guides/cross-platform/live/limitations/

Limited reflection support (currently affecting some of the popular NuGets, such as SQLite and Json.NET). Other NuGets are still supported.

If you compile it into an APK, it works great on the device itself.

Also posted issue here: https://github.com/JamesNK/Newtonsoft.Json/issues/1578

+3
source

Please try this code:

JsonSerializerSettings settings = new JsonSerializerSettings(); settings.ContractResolver = new CamelCasePropertyNamesContractResolver(); var send_Parameter = new { foo = "bar" }; var data = JsonConvert.SerializeObject(send_Parameter, settings); 
0
source

Source: https://habr.com/ru/post/1275491/


All Articles