繁体   English   中英

Cinchoo ETL json 到 csv

[英]Cinchoo ETL json to csv

我正在尝试将 json 格式化为 csv 文件。

这是数据结构

public class Location
{
    [JsonProperty("latitude")]
    public double Latitude { get; set; }

    [JsonProperty("longitude")]
    public double Longitude { get; set; }
}

public class Monitor
{
    [JsonProperty("channelId")]
    public int ChannelId { get; set; }

    [JsonProperty("name")]
    public string Name { get; set; }

    [JsonProperty("alias")]
    public string Alias { get; set; }

    [JsonProperty("active")]
    public bool Active { get; set; }

    [JsonProperty("typeId")]
    public int TypeId { get; set; }

    [JsonProperty("pollutantId")]
    public int PollutantId { get; set; }

    [JsonProperty("units")]
    public string Units { get; set; }

    [JsonProperty("description")]
    public string Description { get; set; }
}

public class StationCall
{
    [JsonProperty("stationId")]
    public int StationId { get; set; }

    [JsonProperty("name")]
    public string Name { get; set; }

    [JsonProperty("shortName")]
    public string ShortName { get; set; }

    [JsonProperty("stationsTag")]
    public string StationsTag { get; set; }

    [JsonProperty("location")]
    public Location Location { get; set; }

    [JsonProperty("timebase")]
    public int Timebase { get; set; }

    [JsonProperty("active")]
    public bool Active { get; set; }

    [JsonProperty("owner")]
    public string Owner { get; set; }

    [JsonProperty("regionId")]
    public int RegionId { get; set; }

    [JsonProperty("monitors")]
    public Monitor[] Monitor { get; set; }

    [JsonProperty("StationTarget")]
    public string StationTarget { get; set; }

    [JsonProperty("additionalTimebases")]
    public string AdditionalTimebases { get; set; }

    [JsonProperty("isNonContinuous")]
    public string IsNonContinuous { get; set; }

    public static string fileName = "stations.txt";
  
   
}

问题出在 csv 结果中,class 监视器格式不正确

StationId,Name,ShortName,StationsTag,Location.Latitude,Location.Longitude,Timebase,Active,Owner,RegionId,Monitor,StationTarget,AdditionalTimebases,IsNonContinuous 63,משושים-דרדרה,Meshushim,Meshushim,00.0000,00.3583,60,True,None ,16,," Sfika_App.Entities.Monitor,Sfika_App.Entities.Monitor,Sfika_App.Entities.Monitor ",无,,

使用 package:

 using (var parser = new ChoCSVWriter<StationCall>("D:/Export.csv").WithFirstLineHeader().UseNestedKeyFormat(true))
        {
            //parser.with
            parser.Write(jsonContent);
        }

我究竟做错了什么?

您将需要使用RangeAttribute装饰Monitor属性以指定可能的预期数组范围

public class StationCall
{
    [JsonProperty("stationId")]
    public int StationId { get; set; }

    [JsonProperty("name")]
    public string Name { get; set; }

    [JsonProperty("shortName")]
    public string ShortName { get; set; }

    [JsonProperty("stationsTag")]
    public string StationsTag { get; set; }

    [JsonProperty("location")]
    public Location Location { get; set; }

    [JsonProperty("timebase")]
    public int Timebase { get; set; }

    [JsonProperty("active")]
    public bool Active { get; set; }

    [JsonProperty("owner")]
    public string Owner { get; set; }

    [JsonProperty("regionId")]
    public int RegionId { get; set; }

    [JsonProperty("monitors")]
    [Range(0, 1)]
    public Monitor[] Monitor { get; set; }

    [JsonProperty("StationTarget")]
    public string StationTarget { get; set; }

    [JsonProperty("additionalTimebases")]
    public string AdditionalTimebases { get; set; }

    [JsonProperty("isNonContinuous")]
    public string IsNonContinuous { get; set; }

    public static string fileName = "stations.txt";
  
   
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM