下面是示例,其中T是一些DTO,我希望得到1 ... n返回与resultCount相匹配的内容.使用Jayrock JsonConvert可以很好地进行加载,但是在尝试反序列化与Jayrock相同的json文本时,它只是向我返回了一个新的JsonResult.
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; }我认为这可能是我在 ServiceStack.Text中询问的问题.JsonSerializer.DeserializeFromString< T>()无法在字符串包含\ n的情况下反序列化,但是即使去掉\ n仍然不允许反序列化成功.
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的JSON序列化器可以支持泛型,但仅序列化公共属性,这是这里的问题.
ServiceStack's JSON Serializer does support generics but only serializes public properties which is the problem here.
[Serializable] 属性在.NET之外的大多数(所有)序列化程序中都没有意义,包括ServiceStack的所有序列化程序.
Also the [Serializable] attribute has no significance in most (all?) serailizers outside of .NET, including all of ServiceStack's serializers.
更多推荐
ServiceStack.Text可以将JSON反序列化为自定义的通用类型吗?
发布评论