回答編集履歴
2
追記
test
CHANGED
@@ -22,6 +22,14 @@
|
|
22
22
|
|
23
23
|
```
|
24
24
|
|
25
|
+
namespace NewtonsoftJson
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
// ・・・中略・・・
|
30
|
+
|
31
|
+
|
32
|
+
|
25
33
|
public class EarthQuake // Rootobject から変更
|
26
34
|
|
27
35
|
{
|
@@ -308,11 +316,13 @@
|
|
308
316
|
|
309
317
|
}
|
310
318
|
|
319
|
+
}
|
320
|
+
|
311
321
|
```
|
312
322
|
|
313
323
|
|
314
324
|
|
315
|
-
上のクラス定義を使って以下のようにデシリアライズできます。
|
325
|
+
上のクラス定義を使って以下のようにデシリアライズできます。(画像に出てくる NewtonsoftJson というのは名前空間名です)
|
316
326
|
|
317
327
|
|
318
328
|
|
1
追記
test
CHANGED
@@ -5,3 +5,315 @@
|
|
5
5
|
JSON 文字列から C# のクラス定義生成
|
6
6
|
|
7
7
|
[http://surferonwww.info/BlogEngine/post/2020/05/10/generate-class-definition-from-json-string.aspx](http://surferonwww.info/BlogEngine/post/2020/05/10/generate-class-definition-from-json-string.aspx)
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
**【2021/4/1 9:55 追記】**
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
https://api.iedred7584.com/eew/json/ から取得できる JSON 文字列から、上の記事で紹介したように VS2019 の機能を使って C# のオブジェクトを生成すると以下のようになります。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
自動生成されたクラス名の Rootobject だけ EarthQuake に変えました。(使った既存のサンプルの他のコードとダブるので)
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
```
|
24
|
+
|
25
|
+
public class EarthQuake // Rootobject から変更
|
26
|
+
|
27
|
+
{
|
28
|
+
|
29
|
+
public string ParseStatus { get; set; }
|
30
|
+
|
31
|
+
public Title Title { get; set; }
|
32
|
+
|
33
|
+
public Source Source { get; set; }
|
34
|
+
|
35
|
+
public Status Status { get; set; }
|
36
|
+
|
37
|
+
public Announcedtime AnnouncedTime { get; set; }
|
38
|
+
|
39
|
+
public Origintime OriginTime { get; set; }
|
40
|
+
|
41
|
+
public string EventID { get; set; }
|
42
|
+
|
43
|
+
public Type Type { get; set; }
|
44
|
+
|
45
|
+
public int Serial { get; set; }
|
46
|
+
|
47
|
+
public Hypocenter Hypocenter { get; set; }
|
48
|
+
|
49
|
+
public Maxintensity MaxIntensity { get; set; }
|
50
|
+
|
51
|
+
public bool Warn { get; set; }
|
52
|
+
|
53
|
+
public Option Option { get; set; }
|
54
|
+
|
55
|
+
public string OriginalText { get; set; }
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
public class Title
|
62
|
+
|
63
|
+
{
|
64
|
+
|
65
|
+
public int Code { get; set; }
|
66
|
+
|
67
|
+
public string String { get; set; }
|
68
|
+
|
69
|
+
public string Detail { get; set; }
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
public class Source
|
76
|
+
|
77
|
+
{
|
78
|
+
|
79
|
+
public int Code { get; set; }
|
80
|
+
|
81
|
+
public string String { get; set; }
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
public class Status
|
88
|
+
|
89
|
+
{
|
90
|
+
|
91
|
+
public string Code { get; set; }
|
92
|
+
|
93
|
+
public string String { get; set; }
|
94
|
+
|
95
|
+
public string Detail { get; set; }
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
public class Announcedtime
|
102
|
+
|
103
|
+
{
|
104
|
+
|
105
|
+
public string String { get; set; }
|
106
|
+
|
107
|
+
public int UnixTime { get; set; }
|
108
|
+
|
109
|
+
public string RFC1123 { get; set; }
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
public class Origintime
|
116
|
+
|
117
|
+
{
|
118
|
+
|
119
|
+
public string String { get; set; }
|
120
|
+
|
121
|
+
public int UnixTime { get; set; }
|
122
|
+
|
123
|
+
public string RFC1123 { get; set; }
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
public class Type
|
130
|
+
|
131
|
+
{
|
132
|
+
|
133
|
+
public int Code { get; set; }
|
134
|
+
|
135
|
+
public string String { get; set; }
|
136
|
+
|
137
|
+
public string Detail { get; set; }
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
public class Hypocenter
|
144
|
+
|
145
|
+
{
|
146
|
+
|
147
|
+
public int Code { get; set; }
|
148
|
+
|
149
|
+
public string Name { get; set; }
|
150
|
+
|
151
|
+
public bool isAssumption { get; set; }
|
152
|
+
|
153
|
+
public Location Location { get; set; }
|
154
|
+
|
155
|
+
public Magnitude Magnitude { get; set; }
|
156
|
+
|
157
|
+
public Accuracy Accuracy { get; set; }
|
158
|
+
|
159
|
+
public bool isSea { get; set; }
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
public class Location
|
166
|
+
|
167
|
+
{
|
168
|
+
|
169
|
+
public float Lat { get; set; }
|
170
|
+
|
171
|
+
public float Long { get; set; }
|
172
|
+
|
173
|
+
public Depth Depth { get; set; }
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
public class Depth
|
180
|
+
|
181
|
+
{
|
182
|
+
|
183
|
+
public int Int { get; set; }
|
184
|
+
|
185
|
+
public string String { get; set; }
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
public class Magnitude
|
192
|
+
|
193
|
+
{
|
194
|
+
|
195
|
+
public float Float { get; set; }
|
196
|
+
|
197
|
+
public string String { get; set; }
|
198
|
+
|
199
|
+
public string LongString { get; set; }
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
public class Accuracy
|
206
|
+
|
207
|
+
{
|
208
|
+
|
209
|
+
public Epicenter Epicenter { get; set; }
|
210
|
+
|
211
|
+
public Depth1 Depth { get; set; }
|
212
|
+
|
213
|
+
public Magnitude1 Magnitude { get; set; }
|
214
|
+
|
215
|
+
public int NumberOfMagnitudeCalculation { get; set; }
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
public class Epicenter
|
222
|
+
|
223
|
+
{
|
224
|
+
|
225
|
+
public int Code { get; set; }
|
226
|
+
|
227
|
+
public string String { get; set; }
|
228
|
+
|
229
|
+
public int Rank2 { get; set; }
|
230
|
+
|
231
|
+
public string String2 { get; set; }
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
public class Depth1
|
238
|
+
|
239
|
+
{
|
240
|
+
|
241
|
+
public int Code { get; set; }
|
242
|
+
|
243
|
+
public string String { get; set; }
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
public class Magnitude1
|
250
|
+
|
251
|
+
{
|
252
|
+
|
253
|
+
public int Code { get; set; }
|
254
|
+
|
255
|
+
public string String { get; set; }
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
public class Maxintensity
|
262
|
+
|
263
|
+
{
|
264
|
+
|
265
|
+
public string From { get; set; }
|
266
|
+
|
267
|
+
public string To { get; set; }
|
268
|
+
|
269
|
+
public string String { get; set; }
|
270
|
+
|
271
|
+
public string LongString { get; set; }
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
public class Option
|
278
|
+
|
279
|
+
{
|
280
|
+
|
281
|
+
public Change Change { get; set; }
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
public class Change
|
288
|
+
|
289
|
+
{
|
290
|
+
|
291
|
+
public int Code { get; set; }
|
292
|
+
|
293
|
+
public string String { get; set; }
|
294
|
+
|
295
|
+
public Reason Reason { get; set; }
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
public class Reason
|
302
|
+
|
303
|
+
{
|
304
|
+
|
305
|
+
public int Code { get; set; }
|
306
|
+
|
307
|
+
public string String { get; set; }
|
308
|
+
|
309
|
+
}
|
310
|
+
|
311
|
+
```
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
上のクラス定義を使って以下のようにデシリアライズできます。
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
![イメージ説明](80d0b1cef4a495c639709039b614572d.jpeg)
|