-
Notifications
You must be signed in to change notification settings - Fork 0
/
JsonExponentialConverter.cs
94 lines (86 loc) · 3.14 KB
/
JsonExponentialConverter.cs
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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TeslaInstituteSpaceWeather
{
public class JsonExponentialConverter : JsonConverter
{
//private readonly Type[] _types;
//public JsonExponentialConverter(params Type[] types)
//{
// _types = types;
//}
public override bool CanRead { get { return true; } }
public override bool CanConvert(Type objectType)
{
return true;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
serializer.Serialize(writer, value);
}
/*
* time_tag : 20.5.2022. 23:00:00
dsflag : 0
dens : 0,95125556
speed : 551,70007
temperature : 120035,93
*/
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
List<Form1.AceSwepam> list = new List<Form1.AceSwepam>();
Form1.AceSwepam item = new Form1.AceSwepam();
int i = -1;
//while (reader.TokenType != JsonToken.EndObject)
while (reader.Read())
{
//reader.Read();
if (reader.Value != null)
{
string key = reader.Value.ToString();
//Console.Write(key);
// ------------------
//Console.Write(" : ");
reader.Read();
float amount = 0;
string val = "";
if (reader.Value == null)
{
amount = 0;
}
else
{
val = reader.Value.ToString();
//Console.WriteLine(val);
}
//if (float.TryParse(reader.Value.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out amount))
{
}
if (reader.Value == null)
{
amount = 0;
} else
float.TryParse(reader.Value.ToString(), out amount);
if (i % 5 == 0) item.time_tag = DateTime.Parse(val);
if (i % 5 == 1) item.dsflag = Int32.Parse(val);
if (i % 5 == 2) item.dens = amount;
if (i % 5 == 3) item.speed = amount;
if (i % 5 == 4) item.temperature = amount;
} // end if
//if (i % 5 == 0) list.Add(item);
if (reader.TokenType == JsonToken.EndObject)
{
list.Add(item);
item = new Form1.AceSwepam();
i = -2;
}
i++;
} // end while
return list;
}
}
}