5

JsonConvert.SerializeObject seems to be not working in xamarin forms. Or i might be missing something here. Here is the output when i serialize a simple object. enter image description here

See it returns {}. I tried serializing a class also and it did return the same.

What could be the problem here?

UPDATE

Still no solution to this issue. I tried creating a simple console application and serializeObject is working on that project so i assume it is not working in xamarin forms only. Does anybody have a xamarin forms project where JSON.NET's serializeobject is working?

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

dbc
  • 104,963
  • 20
  • 228
  • 340
  • You sure this happens only in XamarinForms? Try to create simple console project. Also, which version of Newtonsoft.Json are you using? – eocron Dec 31 '17 at 11:05
  • i tried doing it in a simple console app and it did work. It is on same version of newtonsoft.json. 10.0.3. I will try to downgrade in xamarin and see if it will work on old versions – Voltaire John Secondes Biton Dec 31 '17 at 11:30
  • i tried downgrading and still did not work – Voltaire John Secondes Biton Dec 31 '17 at 11:54
  • Perhaps https://forums.xamarin.com/discussion/16709/jsonconvert-serializeobject-returns may help. – Ralf Bönning Dec 31 '17 at 13:13
  • @RalfBönning i already checked that and it did not work for me. Does anybody have a xamarin project where the JSON.NET serializeobject is working? i tried creating another xamarin project from scratch but still it always return {} for me . so sad – Voltaire John Secondes Biton Jan 02 '18 at 02:33
  • I have found this to be the case with Xamarin Forms when running on an IOS device (iPhone), but SerializeObject works fine on the IOS simulator. No errors, just get a {} returned. – Greg Terrell Jul 05 '18 at 23:24
  • Probable duplicate of [Newtonsoft.Json deserialize object in Xamarin iOS project](https://stackoverflow.com/q/47379055/3744182). – dbc Oct 21 '18 at 14:23

2 Answers2

4

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

Limited support for reflection (currently affects some popular NuGets, like SQLite and Json.NET). Other NuGets are still supported.

If you compile it to an APK it works fine on the actual device.

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

user277754
  • 43
  • 1
  • 3
2

I tried setting up emulator on a fast machine and the serialize works! So it means it doesn't work when i run it on live player using my android phone. I will set this as an answer for now. if someone else posted on how to make it work on live player, i will set it as the correct answer