ServiceStack.Text可以将JSON反序列化为自定义的通用类型吗?

编程入门 行业动态 更新时间:2024-10-10 09:20:35
本文介绍了ServiceStack.Text可以将JSON反序列化为自定义的通用类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

下面是示例,其中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反序列化为自定义的通用类型吗?

本文发布于:2023-11-12 10:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581191.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   序列   类型   ServiceStack   Text

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!