I am trying to format a json to csv file.
here is the the data struct
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";
}
the problem is in the csv result, the class Monitor doesn't format correctly
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",None,,
using the package:
using (var parser = new ChoCSVWriter<StationCall>("D:/Export.csv").WithFirstLineHeader().UseNestedKeyFormat(true))
{
//parser.with
parser.Write(jsonContent);
}
what am i doing wrong?
You will need to decorate the
Monitor
property withRangeAttribute
to specify the possible expected array range