我有一個非常簡單的結構,我想使用牛頓軟 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 關注
- 179 瀏覽
添加回答
舉報
0/150
提交
取消