亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

NewtonSoft Json轉換列表

NewtonSoft Json轉換列表

C#
溫溫醬 2023-08-13 15:59:07
我有一個非常簡單的結構,我想使用牛頓軟 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;

    }

}


查看完整回答
反對 回復 2023-08-13
  • 1 回答
  • 0 關注
  • 179 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號