using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Collections.ObjectModel;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
[JsonProperty("metrics")]
public long metrics { get; set; }
public Map[] map { get; set; }
[JsonConverter(typeof(AlarmsConverter))]
public Alarms Alarm { get; set; }
[JsonProperty("GPRSPoints")]
public GprsPoints GprsPoints { get; set; }
public class AlarmsConverter : JsonConverter<Alarms>
public override Alarms ReadJson(JsonReader reader, Type objectType, Alarms existingValue, bool hasExistingValue, JsonSerializer serializer)
switch (reader.MoveToContentAndAssert().TokenType)
var alarm = hasExistingValue ? existingValue : (Alarms)serializer.ContractResolver.ResolveContract(objectType).DefaultCreator();
serializer.Populate(reader, alarm);
public override bool CanWrite => false;
public override void WriteJson(JsonWriter writer, Alarms value, JsonSerializer serializer) => throw new NotImplementedException();
public static partial class JsonExtensions
public static JsonReader MoveToContentAndAssert(this JsonReader reader)
throw new ArgumentNullException();
if (reader.TokenType == JsonToken.None)
while (reader.TokenType == JsonToken.Comment)
public static JsonReader ReadAndAssert(this JsonReader reader)
throw new ArgumentNullException();
throw new JsonReaderException("Unexpected end of JSON stream.");
public static void Test()
MapResponse result = JsonConvert.DeserializeObject<MapResponse>(res);
var newJson = JsonConvert.SerializeObject(result, Formatting.Indented);
Console.WriteLine("Re-serialized {0}", result);
Console.WriteLine(newJson);
""DataReceived"":""2019-12-16 11:30:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.81026166666667,
""Longitude"":144.962755,
""Alarm"": /* Some Comment */ {
""Alarm"":""Ignition On"",
""AlarmAddress"":""Melbourne Central, Elizabeth Street, Melbourne City, City of Melbourne, Victoria, 3000, Australia"",
""AlarmThreshold"":""0"",
""DataReceived"":""2019-12-16 11:30:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.81026166666667,
""Longitude"":144.962755,
""DataReceived"":""2019-12-16 11:30:27"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.81026166666667,
""Longitude"":144.962755,
""Alarm"":""Fatigue driving"",
""AlarmAddress"":""Melbourne Central, Elizabeth Street, Melbourne City, City of Melbourne, Victoria, 3000, Australia"",
""AlarmThreshold"":""240"",
""DataReceived"":""2019-12-16 11:30:27"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.81026166666667,
""Longitude"":144.962755,
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.81026166666667,
""Longitude"":144.962755,
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.81026166666667,
""Longitude"":144.962755,
""Alarm"":/* Some Comment */ 0
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.81026166666667,
""Longitude"":144.962755,
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.81124166666667,
""Longitude"":144.96304833333335,
""Speed"":1.0799999999999998
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.80994333333334,
""Longitude"":144.962625,
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809958333333334,
""Longitude"":144.96257666666668,
""Speed"":1.5479999999999998
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Longitude"":144.96251333333333,
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.80992666666667,
""Longitude"":144.96246666666667,
""Speed"":0.39599999999999996
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809938333333335,
""Longitude"":144.96243333333334,
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.80994666666667,
""Longitude"":144.962395,
""Speed"":0.7559999999999999
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.80976666666667,
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809868333333334,
""Speed"":0.5399999999999999
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Longitude"":144.96233833333332,
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:20"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:44"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:44"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:44"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:44"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:44"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:44"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:44"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:44"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:49"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:51"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""Alarm"":""Ignition Off"",
""AlarmAddress"":""Aurora Melbourne Central, Little La Trobe Street, Melbourne City, City of Melbourne, Victoria, 3000, Australia"",
""AlarmThreshold"":""0"",
""DataReceived"":""2019-12-16 11:31:51"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""DataReceived"":""2019-12-16 11:31:51"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
""Alarm"":""Fatigue driving"",
""AlarmAddress"":""Aurora Melbourne Central, Little La Trobe Street, Melbourne City, City of Melbourne, Victoria, 3000, Australia"",
""AlarmThreshold"":""240"",
""DataReceived"":""2019-12-16 11:31:51"",
""IgnitionOn"":""2019-12-16 11:30:07"",
""Latitude"":-37.809873333333336,
""Longitude"":144.96232666666666,
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("Json.NET version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];