【发布时间】:2012-11-07 18:31:30
【问题描述】:
我正在使用 Json.net 4.5。我正在使用 JsonConverter 将数据从一个版本转换为另一个版本。
版本 1
public class AV1
{
public string PNr { get; set; } // "x253yN-69Uj"
}
第 2 版
public class AV2
{
public string FirstNr { get; private set; } // "x253yN"
public string LastNr { get; private set; } // "69Uj"
public void SetFirstAndLastNr(string a, string b, string c)
{
//Logic to set the values of FirstNr and LastNr
}
}
在派生的 JsonConverter 中,我正在创建 AV2 类的实例。但是由于属性现在是只读属性,我应该如何设置这些属性的值? Json.net 是否提供任何方法来做同样的事情?还是我必须使用反射?
【问题讨论】:
-
JSON.NET 有很多开箱即用的序列化程序没有的好特性。它甚至被 Microsoft 自己用作其产品之一(ASP.NET Web API)的默认序列化程序。
-
参数
a、b和c在类AV2中的方法SetFirstAndLastNr上是什么意思? -
@carlosfigueira - 参数 a、b、c 是一些用于查询存储库的查询参数,并根据查询结果计算一个唯一编号,该编号现在分为此 FirstNr 和 LastNr。还有其他示例,例如逻辑路径和文档名称等。但我认为我们根本不需要担心这种方法
标签: c# serialization json.net