[英]Can ServiceStack.Text deserialize JSON to a custom generic type?
Example is the following, where T is some DTO that I expect to get 1...n back matching the resultCount. 示例如下,其中T是一些DTO,我希望得到1 ... n返回与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.
使用Jayrock JsonConvert可以很好地进行加载,但是在尝试反序列化Jayrock中使用的相同json文本时,它只是向我返回了一个新的JsonResult。
[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. 我以为这可能是我在ServiceStack.Text.JsonSerializer.DeserializeFromString <T>()处遇到的问题, 如果字符串包含\\ n则无法反序列化 ,但是即使除去那些\\ n仍然不允许反序列化成功。
ServiceStack's JSON Serializer does support generics but only serializes public properties which is the problem here. ServiceStack的JSON序列化器确实支持泛型,但仅序列化公共属性 ,这是这里的问题。
Also the [Serializable]
attribute has no significance in most (all?) serailizers outside of .NET, including all of ServiceStack's serializers. 同样,
[Serializable]
属性在.NET之外的大多数(所有) [Serializable]
中都没有意义,包括所有ServiceStack的序列化程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.