-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGeoNamesToponomyJSONParser.cs
More file actions
193 lines (158 loc) · 7.4 KB
/
Copy pathGeoNamesToponomyJSONParser.cs
File metadata and controls
193 lines (158 loc) · 7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// <auto-generated />
// via https://app.quicktype.io/
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using GeoTagNinja;
//
// var geoResponse = GeoResponse.FromJson(JsonString);
namespace GeoTagNinja.Helpers.API
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class GeoResponseToponomy
{
[JsonProperty("geonames", NullValueHandling = NullValueHandling.Ignore)]
public Geoname[] Geonames { get; set; }
}
public partial class GeoResponseToponomy
{
public static GeoResponseToponomy FromJson(string Json) => JsonConvert.DeserializeObject<GeoResponseToponomy>(Json, GeoTagNinja.Helpers.API.Converter.Settings);
}
public partial class Geoname
{
[JsonProperty("distance", NullValueHandling = NullValueHandling.Ignore)]
public string Distance { get; set; }
[JsonProperty("timezone", NullValueHandling = NullValueHandling.Ignore)]
public Timezone Timezone { get; set; }
[JsonProperty("adminCode1", NullValueHandling = NullValueHandling.Ignore)]
public string AdminCode1 { get; set; }
[JsonProperty("lng", NullValueHandling = NullValueHandling.Ignore)]
public string Lng { get; set; }
[JsonProperty("geonameId", NullValueHandling = NullValueHandling.Ignore)]
public long? GeonameId { get; set; }
[JsonProperty("toponymName", NullValueHandling = NullValueHandling.Ignore)]
public string ToponymName { get; set; }
[JsonProperty("countryId", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(ParseStringConverter))]
public long? CountryId { get; set; }
[JsonProperty("fcl", NullValueHandling = NullValueHandling.Ignore)]
public string Fcl { get; set; }
[JsonProperty("srtm3", NullValueHandling = NullValueHandling.Ignore)]
public long Srtm3 { get; set; }
[JsonProperty("population", NullValueHandling = NullValueHandling.Ignore)]
public long? Population { get; set; }
[JsonProperty("countryCode", NullValueHandling = NullValueHandling.Ignore)]
public string CountryCode { get; set; }
[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
public string Name { get; set; }
[JsonProperty("fclName", NullValueHandling = NullValueHandling.Ignore)]
public string FclName { get; set; }
[JsonProperty("adminCodes1", NullValueHandling = NullValueHandling.Ignore)]
public AdminCodes1 AdminCodes1 { get; set; }
[JsonProperty("countryName", NullValueHandling = NullValueHandling.Ignore)]
public string CountryName { get; set; }
[JsonProperty("fcodeName", NullValueHandling = NullValueHandling.Ignore)]
public string FcodeName { get; set; }
[JsonProperty("adminName1", NullValueHandling = NullValueHandling.Ignore)]
public string AdminName1 { get; set; }
[JsonProperty("adminName2", NullValueHandling = NullValueHandling.Ignore)]
public string AdminName2 { get; set; }
[JsonProperty("adminName3", NullValueHandling = NullValueHandling.Ignore)]
public string AdminName3 { get; set; }
[JsonProperty("adminName4", NullValueHandling = NullValueHandling.Ignore)]
public string AdminName4 { get; set; }
[JsonProperty("lat", NullValueHandling = NullValueHandling.Ignore)]
public string Lat { get; set; }
[JsonProperty("fcode", NullValueHandling = NullValueHandling.Ignore)]
public string Fcode { get; set; }
}
public partial class AdminCodes1
{
[JsonProperty("ISO3166_2", NullValueHandling = NullValueHandling.Ignore)]
public string Iso31662 { get; set; }
}
public partial class Timezone
{
[JsonProperty("gmtOffset")]
public long GmtOffset { get; set; }
[JsonProperty("timeZoneId")]
public string TimeZoneId { get; set; }
[JsonProperty("dstOffset")]
public long DstOffset { get; set; }
}
public partial class GeoResponseTimeZone
{
[JsonProperty("sunrise", NullValueHandling = NullValueHandling.Ignore)]
public string Sunrise { get; set; }
[JsonProperty("lng", NullValueHandling = NullValueHandling.Ignore)]
public double? Lng { get; set; }
[JsonProperty("countryCode", NullValueHandling = NullValueHandling.Ignore)]
public string CountryCode { get; set; }
[JsonProperty("gmtOffset", NullValueHandling = NullValueHandling.Ignore)]
public long? GmtOffset { get; set; }
[JsonProperty("rawOffset", NullValueHandling = NullValueHandling.Ignore)]
public long? RawOffset { get; set; }
[JsonProperty("sunset", NullValueHandling = NullValueHandling.Ignore)]
public string Sunset { get; set; }
[JsonProperty("timezoneId", NullValueHandling = NullValueHandling.Ignore)]
public string TimezoneId { get; set; }
[JsonProperty("dstOffset", NullValueHandling = NullValueHandling.Ignore)]
public long? DstOffset { get; set; }
[JsonProperty("countryName", NullValueHandling = NullValueHandling.Ignore)]
public string CountryName { get; set; }
[JsonProperty("time", NullValueHandling = NullValueHandling.Ignore)]
public string Time { get; set; }
[JsonProperty("lat", NullValueHandling = NullValueHandling.Ignore)]
public double? Lat { get; set; }
}
public partial class GeoResponseTimeZone
{
public static GeoResponseTimeZone FromJson(string Json) => JsonConvert.DeserializeObject<GeoResponseTimeZone>(Json, GeoTagNinja.Helpers.API.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this GeoResponseToponomy self) => JsonConvert.SerializeObject(self, GeoTagNinja.Helpers.API.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
internal class ParseStringConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(long) || t == typeof(long?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<string>(reader);
long l;
if (Int64.TryParse(value, out l))
{
return l;
}
throw new Exception("Cannot unmarshal type long");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (long)untypedValue;
serializer.Serialize(writer, value.ToString());
return;
}
public static readonly ParseStringConverter Singleton = new ParseStringConverter();
}
}