Xamarin Using DataContractJsonSerializer for Android Blank App

时间秒杀一切 提交于 2019-12-25 01:59:46

问题


I am trying to use DataContractJsonSerializer but I can't seem to get a reference/namespace for it. I created my app on a .NET Framework 4.5.

When I click add reference I only get the version 2.0.5.0 for System.ServiceModel


回答1:


If you want to get DataContractJsonSerializer working with Android you would need to create a PCL project and then it would be available under namespace System.Runtime.Serialization.Json. This would require a Xamarin business license or higher to work.

Better option would be to use Json.NET (much faster than DataContractJsonSerializer if you use it more than once) or ServiceStack.Text (much faster than Json.NET). XLabs offers an abstraction on mobile compatible serializers (Nuget, search for XLabs.Serialization) and has plugins for Json.NET, ServiceStack.Text (v3), ProtoBuf & of course DataContractSerializer (.NET XML serializer). DataContractJsonSerializer is omitted from the package since it requires business license and really doesn't offer much over Json.NET or ServiceStack.




回答2:


DataContractJsonSerializer will not work with Xamarin. I use Newtonsoft.Json nuget package to work with json serialization and till now haven't found any problem with it. It's very simple:

string str = Newtonsoft.Json.JsonConvert.SerializeObject(myObject);



来源:https://stackoverflow.com/questions/29539221/xamarin-using-datacontractjsonserializer-for-android-blank-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!