我有一个非常简单的结构,我想使用牛顿软 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);
我究竟做错了什么?该示例表明这是可能的...
森栏
相关分类