我有一个非常简单的结构,我想使用牛顿软 Json 序列化来序列化。定义:public enum SensorType{ Temperature, Flow, Pressure}public enum SensorLocation{ Manifold, TopVessel, WaferStage}[JsonArray]public class SensorConfiguration{ [JsonProperty] public string Name { get; set; } [JsonConverter(typeof(StringEnumConverter))] public SensorType Type { get; set; } [JsonConverter(typeof(StringEnumConverter))] public SensorLocation Location { get; set; } public SensorConfiguration() { } public SensorConfiguration(string name, SensorType type, SensorLocation location) { Name = name; Type = type; Location = location; }}序列化: var topvessel = Sensors.TopVessel.Select(sensor => new SensorConfiguration(sensor.SensorName, sensor.Type, SensorLocation.TopVessel)); var manifold = Sensors.Manifold.Select(sensor => new SensorConfiguration(sensor.SensorName, sensor.Type, SensorLocation.Manifold)); var waferstage = Sensors.WaferStage.Select(sensor => new SensorConfiguration(sensor.SensorName, sensor.Type, SensorLocation.Manifold)); var sensorConfigurations = topvessel.Concat(manifold).Concat(waferstage).ToList(); var json = JsonConvert.SerializeObject(sensorConfigurations);我究竟做错了什么?该示例表明这是可能的...
1 回答
森栏
TA贡献1810条经验 获得超5个赞
尝试删除[JsonArray]
所以你的代码看起来像
public class SensorConfiguration
{
[JsonProperty]
public string Name { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public SensorType Type { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public SensorLocation Location { get; set; }
public SensorConfiguration()
{
}
public SensorConfiguration(string name, SensorType type, SensorLocation location)
{
Name = name;
Type = type;
Location = location;
}
}
- 1 回答
- 0 关注
- 118 浏览
添加回答
举报
0/150
提交
取消