ich habe eine Json-Datei die je nach Element verschiedene Typen enthält. Wie kann ich eine Json-Datei mal in eine Klasse mal in eine andere Klasse mappen ?
Ich arbeite mit Newtonsoft.
Quelle der Json-Datei : http://download.seven-c.de/files/finderwille-frankfurt/einsatz-app/geojson/Hessen_Landkreise.geojson
Die Datei kommt hierher : http://opendatalab.de/projects/geojson-utilities/
Wenn ich mit Json-Util eine Klasse erzeuge kommt mal das eine mal das andere raus.
Der Unterschied liegt in der Klasse GeoJsonGeometry1/2, da sind die Koordinaten einmal eine dreifach verschachtelte Liste, einmal vierfach.
Liegt wohl daran dass es Landkreisgrenzen gibt die aus einem Polygon bestehen und die Bergstraße besteht z.B. aus 3 Plygonen.
Ich würde gerne in Klassen mappen ohne in den Json-Dateien rumzufuddeln.
Grüße Bernd
// Landkreise außer Bergstraße
public class GeoJsonProperties1
{
public string name { get; set; }
}
public class GeoJsonCrs1
{
public string type { get; set; }
public GeoJsonProperties1 properties { get; set; }
}
public class GeoJsonGeometry1
{
public string type { get; set; }
public IList<IList<IList<double>>> coordinates { get; set; }
}
public class GeoJsonFeature1
{
public string type { get; set; }
public GeoJsonProperties1 properties { get; set; }
public GeoJsonGeometry1 geometry { get; set; }
}
public class GeoJson1
{
public string type { get; set; }
public GeoJsonCrs1 crs { get; set; }
public string source { get; set; }
public IList<GeoJsonFeature1> features { get; set; }
}
// Bergstraße
public class GeoJsonProperties2
{
public string name { get; set; }
}
public class GeoJsonCrs2
{
public string type { get; set; }
public GeoJsonProperties2 properties { get; set; }
}
public class GeoJsonGeometry2
{
public string type { get; set; }
public IList<IList<IList<IList<double>>>> coordinates { get; set; }
}
public class GeoJsonFeature2
{
public string type { get; set; }
public GeoJsonProperties2 properties { get; set; }
public GeoJsonGeometry2 geometry { get; set; }
}
public class GeoJson2
{
public string type { get; set; }
public GeoJsonCrs2 crs { get; set; }
public string source { get; set; }
public IList<GeoJsonFeature2> features { get; set; }
}