Can ServiceStack.Text deserialize JSON to a custom generic type?

天大地大妈咪最大 提交于 2019-12-11 02:39:37

问题


Example is the following, where T is some DTO that I expect to get 1...n back matching the resultCount. This loaded up fine using Jayrock JsonConvert, however is just returning a new JsonResult to me when trying to deserialize the same json text that worked in Jayrock.

[Serializable]
public class JsonResult<T>
{
  public int resultCount = 0;
  public T[] results;
} 

I thought this might be an issue that I asked about at ServiceStack.Text.JsonSerializer.DeserializeFromString<T>() fails to deserialize if string contains \n's, however even stripping out those \n's still doesn't allow deserialization to succeed.


回答1:


ServiceStack's JSON Serializer does support generics but only serializes public properties which is the problem here.

Also the [Serializable] attribute has no significance in most (all?) serailizers outside of .NET, including all of ServiceStack's serializers.



来源:https://stackoverflow.com/questions/12771101/can-servicestack-text-deserialize-json-to-a-custom-generic-type

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