From 091f578c7fbd74ac1b1dd74e10323ea2e3cb7cc8 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Wed, 7 Sep 2016 19:14:13 +0200
Subject: [PATCH] adapted writing of json content

---
 VECTO/AdvancedAuxiliariesModule.vb |  2 +-
 VECTO/Configuration.vb             | 37 +++++++++---------
 VECTO/GUI/MainForm.vb              | 11 +++++-
 VECTO/GUI/VectoJobForm.vb          | 10 ++++-
 VECTO/GUI/VehicleForm.vb           | 36 ++++++++++--------
 VECTO/Input Files/Engine.vb        | 43 ++++++++++-----------
 VECTO/Input Files/Gearbox.vb       | 53 +++++++++++++-------------
 VECTO/Input Files/VectoJob.vb      | 42 ++++++++++----------
 VECTO/Input Files/Vehicle.vb       | 61 +++++++++++++++---------------
 VECTO/JSONparser.vb                | 44 ++-------------------
 VECTO/VECTO.vbproj                 |  2 +
 11 files changed, 159 insertions(+), 182 deletions(-)

diff --git a/VECTO/AdvancedAuxiliariesModule.vb b/VECTO/AdvancedAuxiliariesModule.vb
index 0d2bcfc212..c56ab64f15 100644
--- a/VECTO/AdvancedAuxiliariesModule.vb
+++ b/VECTO/AdvancedAuxiliariesModule.vb
@@ -11,7 +11,7 @@ Module AdvancedAuxiliariesModule
 									ByVal messageType As AdvancedAuxiliaryMessageType) Handles advancedAuxModel.AuxiliaryEvent
 
 
-		WorkerMsg(messageType, message, "Advanced Auxiliaries")
+		WorkerMsg(CType(messageType, MessageType), message, "Advanced Auxiliaries")
 	End Sub
 
 	'AA-TB
diff --git a/VECTO/Configuration.vb b/VECTO/Configuration.vb
index 65ee58a6e0..64d7ca2a4f 100644
--- a/VECTO/Configuration.vb
+++ b/VECTO/Configuration.vb
@@ -90,28 +90,27 @@ Public Class Configuration
 
 	Public Sub Save()
 		Dim json As New JSONParser
-		Dim dic As Dictionary(Of String, Object)
 
-		dic = New Dictionary(Of String, Object)
-		dic.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")")
-		dic.Add("Date", Now.ToUniversalTime().ToString("o"))
-		dic.Add("AppVersion", VECTOvers)
-		dic.Add("FileVersion", FormatVersion)
-		json.Content.Add("Header", JToken.FromObject(dic))
+		Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
+		header.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")")
+		header.Add("Date", Now.ToUniversalTime().ToString("o"))
+		header.Add("AppVersion", VECTOvers)
+		header.Add("FileVersion", FormatVersion)
 
-		dic = New Dictionary(Of String, Object)
-		dic.Add("ModOut", ModOut)
-		dic.Add("Mod1Hz", Mod1Hz)
-		dic.Add("LogSize", LogSize)
-		dic.Add("AirDensity", AirDensity)
-		dic.Add("FuelDensity", FuelDens)
-		dic.Add("CO2perFC", CO2perFC)
-		dic.Add("OpenCmd", OpenCmd)
-		dic.Add("OpenCmdName", OpenCmdName)
-		dic.Add("FirstRun", FirstRun)
-		dic.Add("DeclMode", DeclMode)
-		json.Content.Add("Body", JToken.FromObject(dic))
 
+		Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
+		body.Add("ModOut", ModOut)
+		body.Add("Mod1Hz", Mod1Hz)
+		body.Add("LogSize", LogSize)
+		body.Add("AirDensity", AirDensity)
+		body.Add("FuelDensity", FuelDens)
+		body.Add("CO2perFC", CO2perFC)
+		body.Add("OpenCmd", OpenCmd)
+		body.Add("OpenCmdName", OpenCmdName)
+		body.Add("FirstRun", FirstRun)
+		body.Add("DeclMode", DeclMode)
+
+		json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}})
 		json.WriteFile(FilePath)
 	End Sub
 End Class
diff --git a/VECTO/GUI/MainForm.vb b/VECTO/GUI/MainForm.vb
index 1bc09c7026..b0b4ee56b3 100644
--- a/VECTO/GUI/MainForm.vb
+++ b/VECTO/GUI/MainForm.vb
@@ -365,7 +365,11 @@ Public Class MainForm
 						If VehicleForm.WindowState = FormWindowState.Minimized Then VehicleForm.WindowState = FormWindowState.Normal
 						VehicleForm.BringToFront()
 					End If
-					VehicleForm.OpenVehicle(File)
+					Try
+						VehicleForm.OpenVehicle(File)
+					Catch ex As Exception
+						MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error loading Vehicle File")
+					End Try
 				Case ".VENG"
 					If Not EngineForm.Visible Then
 						EngineForm.Show()
@@ -939,7 +943,10 @@ lbFound:
 	End Sub
 
 
-	Private Sub VectoWorkerV3_OnDoWork(sender As BackgroundWorker, e As DoWorkEventArgs)
+	Private Sub VectoWorkerV3_OnDoWork(theSender As Object, e As DoWorkEventArgs)
+		Dim sender As BackgroundWorker = TryCast(theSender, BackgroundWorker)
+		If sender Is Nothing Then Exit Sub
+
 		AllowSleepOFF()
 
 		Dim sumFileWriter As FileOutputWriter = New FileOutputWriter(JobFileList(0))
diff --git a/VECTO/GUI/VectoJobForm.vb b/VECTO/GUI/VectoJobForm.vb
index c8af0b15b1..506de305ee 100644
--- a/VECTO/GUI/VectoJobForm.vb
+++ b/VECTO/GUI/VectoJobForm.vb
@@ -232,7 +232,13 @@ Public Class VectoJobForm
 			VehicleForm.BringToFront()
 		End If
 
-		If Not Trim(f) = "" Then VehicleForm.OpenVehicle(f)
+		If Not Trim(f) = "" Then
+			Try
+				VehicleForm.OpenVehicle(f)
+			Catch ex As Exception
+				MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error loading Vehicle File")
+			End Try
+		End If
 	End Sub
 
 	'Open Engine Editor
@@ -1010,7 +1016,7 @@ lbDlog:
 
 		VEH0.FilePath = fFileRepl(TbVEH.Text, GetPath(VECTOfile))
 		If VEH0.ReadFile(False) Then
-			Dim maxMass = (VEH0.MassMax * 1000).SI(Of Kilogram)()				  'CSng(fTextboxToNumString(TbMassMass.Text))
+			Dim maxMass = (VEH0.MassMax * 1000).SI(Of Kilogram)()				   'CSng(fTextboxToNumString(TbMassMass.Text))
 
 			Dim s0 As Segment = Nothing
 			Try
diff --git a/VECTO/GUI/VehicleForm.vb b/VECTO/GUI/VehicleForm.vb
index 417ec287cb..ee1f76436e 100644
--- a/VECTO/GUI/VehicleForm.vb
+++ b/VECTO/GUI/VehicleForm.vb
@@ -192,7 +192,14 @@ Public Class VehicleForm
 
 	'Open
 	Private Sub ToolStripBtOpen_Click(sender As Object, e As EventArgs) Handles ToolStripBtOpen.Click
-		If VehicleFileBrowser.OpenDialog(_vehFile) Then OpenVehicle(VehicleFileBrowser.Files(0))
+		If VehicleFileBrowser.OpenDialog(_vehFile) Then
+			Try
+				OpenVehicle(VehicleFileBrowser.Files(0))
+			Catch ex As Exception
+				MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error loading Vehicle File")
+			End Try
+
+		End If
 	End Sub
 
 	'Save
@@ -330,6 +337,10 @@ Public Class VehicleForm
 			End Select
 		End If
 
+		CbCat.SelectedValue = veh.VehicleCategory
+		CbAxleConfig.SelectedValue = veh.AxleConfiguration
+		TbMassMass.Text = veh.MassMax.ToGUIFormat()
+
 		TbMass.Text = veh.Mass.ToGUIFormat()
 		TbMassExtra.Text = veh.MassExtra.ToGUIFormat()
 		TbLoad.Text = veh.Loading.ToGUIFormat()
@@ -346,9 +357,6 @@ Public Class VehicleForm
 		tbAngularGearRatio.Text = veh.AngularGearRatio.ToGUIFormat()
 		tbAngularGearLossMapPath.Text = veh.AngularGearLossMapFile.OriginalPath
 
-		CbCat.SelectedValue = veh.VehicleCategory
-
-
 		LvRRC.Items.Clear()
 		Dim i = 0
 		For Each a0 In veh.Axles
@@ -365,10 +373,8 @@ Public Class VehicleForm
 
 		Next
 
-		TbMassMass.Text = veh.MassMax.ToGUIFormat()
-		TbMassExtra.Text = veh.MassExtra.ToGUIFormat()
 
-		CbAxleConfig.SelectedValue = veh.AxleConfiguration
+		TbMassExtra.Text = veh.MassExtra.ToGUIFormat()
 
 		TBcdA.Text = veh.CdA0.ToGUIFormat()
 
@@ -416,12 +422,12 @@ Public Class VehicleForm
 		veh.FilePath = file
 
 		veh.Mass = TbMass.Text.ToDouble()
-		veh.MassExtra = TbMassExtra.Text.ToDouble()
-		veh.Loading = TbLoad.Text.ToDouble()
+		veh.MassExtra = TbMassExtra.Text.ToDouble(0)
+		veh.Loading = TbLoad.Text.ToDouble(0)
 
 		veh.CdA0 = TBcdA.Text.ToDouble()
 
-		veh.DynamicTyreRadius = TBrdyn.Text.ToDouble()
+		veh.DynamicTyreRadius = TBrdyn.Text.ToDouble(0)
 		veh.CrossWindCorrectionMode = CType(CbCdMode.SelectedValue, CrossWindCorrectionMode)
 		veh.CrossWindCorrectionFile.Init(GetPath(file), TbCdFile.Text)
 		veh.RetarderType = CType(CbRtType.SelectedValue, RetarderType)
@@ -437,13 +443,13 @@ Public Class VehicleForm
 		Dim axleShareCheck As Double
 		For Each entry As ListViewItem In LvRRC.Items
 			Dim a0 = New Vehicle.Axle
-			a0.Share = entry.SubItems(AxleTbl.RelativeLoad).Text.ToDouble()
+			a0.Share = entry.SubItems(AxleTbl.RelativeLoad).Text.ToDouble(0)
 			axleShareCheck += a0.Share
 			a0.TwinTire = (entry.SubItems(AxleTbl.TwinTyres).Text = "yes")
-			a0.RRC = entry.SubItems(AxleTbl.RRC).Text.ToDouble()
-			a0.FzISO = entry.SubItems(AxleTbl.FzISO).Text.ToDouble()
+			a0.RRC = entry.SubItems(AxleTbl.RRC).Text.ToDouble(0)
+			a0.FzISO = entry.SubItems(AxleTbl.FzISO).Text.ToDouble(0)
 			a0.Wheels = entry.SubItems(AxleTbl.WheelsDimension).Text
-			a0.Inertia = entry.SubItems(AxleTbl.Inertia).Text.ToDouble()
+			a0.Inertia = entry.SubItems(AxleTbl.Inertia).Text.ToDouble(0)
 			veh.Axles.Add(a0)
 		Next
 
@@ -457,7 +463,7 @@ Public Class VehicleForm
 		End If
 
 		veh.MassMax = TbMassMass.Text.ToDouble()
-		veh.MassExtra = TbMassExtra.Text.ToDouble()
+		veh.MassExtra = TbMassExtra.Text.ToDouble(0)
 		veh.AxleConfiguration = CType(CbAxleConfig.SelectedValue, AxleConfiguration)
 
 
diff --git a/VECTO/Input Files/Engine.vb b/VECTO/Input Files/Engine.vb
index 9c50cfc05d..9a9d25876e 100644
--- a/VECTO/Input Files/Engine.vb	
+++ b/VECTO/Input Files/Engine.vb	
@@ -141,42 +141,38 @@ Public Class Engine
 	''' <returns>True if successful.</returns>
 	''' <remarks></remarks>
 	Public Function SaveFile() As Boolean
-		Dim JSON As New JSONParser
-		Dim dic As Dictionary(Of String, Object)
+		Dim json As New JSONParser
 
 		'Header
-		dic = New Dictionary(Of String, Object)
-		dic.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")")
-		dic.Add("Date", Now.ToUniversalTime().ToString("o"))
-		dic.Add("AppVersion", VECTOvers)
-		dic.Add("FileVersion", FormatVersion)
-		JSON.Content.Add("Header", JToken.FromObject(dic))
+		Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
+		header.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")")
+		header.Add("Date", Now.ToUniversalTime().ToString("o"))
+		header.Add("AppVersion", VECTOvers)
+		header.Add("FileVersion", FormatVersion)
 
 		'Body
-		dic = New Dictionary(Of String, Object)
+		Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
 
-		dic.Add("SavedInDeclMode", Cfg.DeclMode)
+		body.Add("SavedInDeclMode", Cfg.DeclMode)
 		SavedInDeclMode = Cfg.DeclMode
 
-		dic.Add("ModelName", ModelName)
-
-		dic.Add("Displacement", Displacement)
-		dic.Add("IdlingSpeed", IdleSpeed)
-		dic.Add("Inertia", EngineInertia)
+		body.Add("ModelName", ModelName)
 
-		dic.Add("FullLoadCurve", _fullLoadCurvePath.PathOrDummy)
+		body.Add("Displacement", Displacement)
+		body.Add("IdlingSpeed", IdleSpeed)
+		body.Add("Inertia", EngineInertia)
 
-		dic.Add("FuelMap", _fuelConsumptionMapPath.PathOrDummy)
+		body.Add("FullLoadCurve", _fullLoadCurvePath.PathOrDummy)
 
-		dic.Add("WHTC-Urban", WHTCurban)
-		dic.Add("WHTC-Rural", WHTCrural)
-		dic.Add("WHTC-Motorway", WHTCmw)
+		body.Add("FuelMap", _fuelConsumptionMapPath.PathOrDummy)
 
+		body.Add("WHTC-Urban", WHTCurban)
+		body.Add("WHTC-Rural", WHTCrural)
+		body.Add("WHTC-Motorway", WHTCmw)
 
-		JSON.Content.Add("Body", JToken.FromObject(dic))
+		json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}})
 
-
-		Return JSON.WriteFile(_filePath)
+		Return json.WriteFile(_filePath)
 	End Function
 
 	''' <summary>
@@ -290,3 +286,4 @@ Public Class Engine
 	End Property
 End Class
 
+
diff --git a/VECTO/Input Files/Gearbox.vb b/VECTO/Input Files/Gearbox.vb
index 46f44f4bf1..97359c9f52 100644
--- a/VECTO/Input Files/Gearbox.vb	
+++ b/VECTO/Input Files/Gearbox.vb	
@@ -98,26 +98,25 @@ Public Class Gearbox
 	Public Function SaveFile() As Boolean
 		Dim i As Integer
 		Dim json As New JSONParser
-		Dim content As Dictionary(Of String, Object)
 
 		'Header
-		content = New Dictionary(Of String, Object)
-		content.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")")
-		content.Add("Date", Now.ToUniversalTime().ToString("o"))
-		content.Add("AppVersion", VECTOvers)
-		content.Add("FileVersion", FormatVersion)
-		json.Content.Add("Header", JToken.FromObject(content))
+		Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
+		header.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")")
+		header.Add("Date", Now.ToUniversalTime().ToString("o"))
+		header.Add("AppVersion", VECTOvers)
+		header.Add("FileVersion", FormatVersion)
+
 
 		'Body
-		content = New Dictionary(Of String, Object)
+		Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
 
-		content.Add("SavedInDeclMode", Cfg.DeclMode)
+		body.Add("SavedInDeclMode", Cfg.DeclMode)
 		SavedInDeclMode = Cfg.DeclMode
 
-		content.Add("ModelName", ModelName)
+		body.Add("ModelName", ModelName)
 
-		content.Add("Inertia", GbxInertia)
-		content.Add("TracInt", TracIntrSi)
+		body.Add("Inertia", GbxInertia)
+		body.Add("TracInt", TracIntrSi)
 
 		Dim ls As New List(Of Object)
 		For i = 0 To GearRatios.Count - 1
@@ -135,18 +134,18 @@ Public Class Gearbox
 
 			ls.Add(gearDict)
 		Next
-		content.Add("Gears", ls)
+		body.Add("Gears", ls)
 
-		content.Add("TqReserve", TorqueResv)
-		content.Add("SkipGears", SkipGears)
-		content.Add("ShiftTime", ShiftTime)
-		content.Add("EaryShiftUp", ShiftInside)
+		body.Add("TqReserve", TorqueResv)
+		body.Add("SkipGears", SkipGears)
+		body.Add("ShiftTime", ShiftTime)
+		body.Add("EaryShiftUp", ShiftInside)
 
-		content.Add("StartTqReserve", TorqueResvStart)
-		content.Add("StartSpeed", StartSpeed)
-		content.Add("StartAcc", StartAcc)
+		body.Add("StartTqReserve", TorqueResvStart)
+		body.Add("StartSpeed", StartSpeed)
+		body.Add("StartAcc", StartAcc)
 
-		content.Add("GearboxType", Type)
+		body.Add("GearboxType", Type)
 
 		Dim torqueConverterDict As New Dictionary(Of String, Object)
 		torqueConverterDict.Add("Enabled", TorqueConverterEnabled)
@@ -154,14 +153,14 @@ Public Class Gearbox
 		torqueConverterDict.Add("RefRPM", TorqueConverterReferenceRpm)
 		torqueConverterDict.Add("Inertia", TorqueConverterInertia)
 		torqueConverterDict.Add("ShiftPolygon", TorqueConverterShiftPolygonFile)
-		content.Add("TorqueConverter", torqueConverterDict)
+		body.Add("TorqueConverter", torqueConverterDict)
 
 
-		content.Add("DownshiftAferUpshiftDelay", DownshiftAfterUpshift)
-		content.Add("UpshiftAfterDownshiftDelay", UpshiftAfterDownshift)
-		content.Add("UpshiftMinAcceleration", UpshiftMinAcceleration)
+		body.Add("DownshiftAferUpshiftDelay", DownshiftAfterUpshift)
+		body.Add("UpshiftAfterDownshiftDelay", UpshiftAfterDownshift)
+		body.Add("UpshiftMinAcceleration", UpshiftMinAcceleration)
 
-		json.Content.Add("Body", JToken.FromObject(content))
+		json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}})
 
 		Return json.WriteFile(_filePath)
 	End Function
@@ -202,7 +201,7 @@ Public Class Gearbox
 				If dic("Efficiency") Is Nothing Then
 					GearLossmaps(i).Init(_myPath, dic.GetEx(Of String)("LossMap"))
 				Else
-					GearLossmaps(i).Init(_myPath, dic.GetEx(Of Double)("Efficiency"))
+					GearLossmaps(i).Init(_myPath, dic.GetEx(Of Double)("Efficiency").ToString())
 				End If
 
 				MaxTorque.Add(dic.GetEx(Of String)("MaxTorque"))
diff --git a/VECTO/Input Files/VectoJob.vb b/VECTO/Input Files/VectoJob.vb
index aa63f4e73c..d2b414b0e3 100644
--- a/VECTO/Input Files/VectoJob.vb	
+++ b/VECTO/Input Files/VectoJob.vb	
@@ -89,36 +89,36 @@ Public Class VectoJob
 		Dim json As New JSONParser
 
 		'Header
-		json.Content.Add("Header", JToken.FromObject(New Dictionary(Of String, Object) From {
-														{"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"},
-														{"Date", Now.ToUniversalTime().ToString("o")},
-														{"AppVersion", VECTOvers},
-														{"FileVersion", FormatVersion}}))
+		Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From {
+				{"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"},
+				{"Date", Now.ToUniversalTime().ToString("o")},
+				{"AppVersion", VECTOvers},
+				{"FileVersion", FormatVersion}}
 
 		'Body
-		Dim dic0 = New Dictionary(Of String, Object)
+		Dim body = New Dictionary(Of String, Object)
 
-		dic0.Add("SavedInDeclMode", Cfg.DeclMode)
+		body.Add("SavedInDeclMode", Cfg.DeclMode)
 		SavedInDeclMode = Cfg.DeclMode
 
 		'Main Files
-		dic0.Add("VehicleFile", _vehicleFile.PathOrDummy)
-		dic0.Add("EngineFile", _engineFile.PathOrDummy)
-		dic0.Add("GearboxFile", _gearboxFile.PathOrDummy)
+		body.Add("VehicleFile", _vehicleFile.PathOrDummy)
+		body.Add("EngineFile", _engineFile.PathOrDummy)
+		body.Add("GearboxFile", _gearboxFile.PathOrDummy)
 
 		'Cycles
 		If CycleFiles.Count > 0 Then
-			dic0.Add("Cycles", CycleFiles.Select(Function(sb) sb.PathOrDummy))
+			body.Add("Cycles", CycleFiles.Select(Function(sb) sb.PathOrDummy))
 		End If
 
 		'AA-TB
 		'ADVANCED AUXILIARIES 
-		dic0.Add("AuxiliaryAssembly", AuxiliaryAssembly)
-		dic0.Add("AuxiliaryVersion", AuxiliaryVersion)
-		dic0.Add("AdvancedAuxiliaryFilePath", AdvancedAuxiliaryFilePath)
+		body.Add("AuxiliaryAssembly", AuxiliaryAssembly)
+		body.Add("AuxiliaryVersion", AuxiliaryVersion)
+		body.Add("AdvancedAuxiliaryFilePath", AdvancedAuxiliaryFilePath)
 
 		If AuxPaths.Any() Then
-			dic0.Add("Aux", AuxPaths.Select(Function(kv) New Dictionary(Of String, Object) From {
+			body.Add("Aux", AuxPaths.Select(Function(kv) New Dictionary(Of String, Object) From {
 												{"ID", Trim(UCase(kv.Key))},
 												{"Type", kv.Value.Type},
 												{"Path", kv.Value.Path.PathOrDummy},
@@ -126,14 +126,14 @@ Public Class VectoJob
 												}))
 		End If
 
-		dic0.Add("VACC", _driverAccelerationFile.PathOrDummy)
-		dic0.Add("EngineOnlyMode", EngineOnly)
-		dic0.Add("StartStop", New Dictionary(Of String, Object) From {
+		body.Add("VACC", _driverAccelerationFile.PathOrDummy)
+		body.Add("EngineOnlyMode", EngineOnly)
+		body.Add("StartStop", New Dictionary(Of String, Object) From {
 					{"Enabled", _startStop},
 					{"MaxSpeed", _startStopMaxSpeed},
 					{"MinTime", _startStopMinTime},
 					{"Delay", StartStopDelay}})
-		dic0.Add("LAC", New Dictionary(Of String, Object) From {
+		body.Add("LAC", New Dictionary(Of String, Object) From {
 					{"Enabled", LookAheadOn},
 					{"PreviewDistanceFactor", LacPreviewFactor},
 					{"DF_offset", LacDfOffset},
@@ -153,9 +153,9 @@ Public Class VectoJob
 		overspeedDic.Add("MinSpeed", VMin)
 		overspeedDic.Add("OverSpeed", OverSpeed)
 		overspeedDic.Add("UnderSpeed", UnderSpeed)
-		dic0.Add("OverSpeedEcoRoll", overspeedDic)
+		body.Add("OverSpeedEcoRoll", overspeedDic)
 
-		json.Content.Add("Body", JToken.FromObject(dic0))
+		json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}})
 		Return json.WriteFile(_sFilePath)
 	End Function
 
diff --git a/VECTO/Input Files/Vehicle.vb b/VECTO/Input Files/Vehicle.vb
index 4d68c985ff..d2b017048a 100644
--- a/VECTO/Input Files/Vehicle.vb	
+++ b/VECTO/Input Files/Vehicle.vb	
@@ -124,7 +124,7 @@ Public Class Vehicle
 		If Not json.ReadFile(_filePath) Then Return False
 
 		Try
-			Dim header As jtoken = json.Content.GetEx("Header")
+			Dim header As JToken = json.Content.GetEx("Header")
 			Dim body As JToken = json.Content.GetEx("Body")
 
 			_fileVersion = header.GetEx(Of Integer)("FileVersion")
@@ -253,49 +253,48 @@ Public Class Vehicle
 
 		Dim json As New JSONParser
 		'Header
-		json.Content.Add("Header", JToken.FromObject(New Dictionary(Of String, Object) From {
-														{"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"},
-														{"Date", Now.ToUniversalTime().ToString("o")},
-														{"AppVersion", VECTOvers},
-														{"FileVersion", FormatVersion}}))
+		Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From {
+				{"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"},
+				{"Date", Now.ToUniversalTime().ToString("o")},
+				{"AppVersion", VECTOvers},
+				{"FileVersion", FormatVersion}}
 
 		'Body
-		Dim dic As Dictionary(Of String, Object)
-		dic = New Dictionary(Of String, Object) From {
-			{"SavedInDeclMode", Cfg.DeclMode},
-			{"VehCat", VehicleCategory.ToString()},
-			{"CurbWeight", Mass},
-			{"CurbWeightExtra", MassExtra},
-			{"Loading", Loading},
-			{"MassMax", MassMax},
-			{"CdA", CdA0},
-			{"rdyn", DynamicTyreRadius},
-			{"CdCorrMode", CrossWindCorrectionMode.GetName()},
-			{"CdCorrFile", CrossWindCorrectionFile.PathOrDummy},
-			{"Retarder", New Dictionary(Of String, Object) From {
+		Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From {
+				{"SavedInDeclMode", Cfg.DeclMode},
+				{"VehCat", VehicleCategory.ToString()},
+				{"CurbWeight", Mass},
+				{"CurbWeightExtra", MassExtra},
+				{"Loading", Loading},
+				{"MassMax", MassMax},
+				{"CdA", CdA0},
+				{"rdyn", DynamicTyreRadius},
+				{"CdCorrMode", CrossWindCorrectionMode.GetName()},
+				{"CdCorrFile", CrossWindCorrectionFile.PathOrDummy},
+				{"Retarder", New Dictionary(Of String, Object) From {
 				{"Type", RetarderType.GetName()},
 				{"Ratio", RetarderRatio},
 				{"File", RetarderLossMapFile.PathOrDummy}}},
-			{"AngularGear", New Dictionary(Of String, Object) From {
+				{"AngularGear", New Dictionary(Of String, Object) From {
 				{"Type", AngularGearType.ToString()},
 				{"Ratio", AngularGearRatio},
 				{"LossMap", AngularGearLossMapFile.PathOrDummy}}},
-			{"PTO", New Dictionary(Of String, Object) From {
+				{"PTO", New Dictionary(Of String, Object) From {
 				{"Type", PTOType},
 				{"LossMap", PTOLossMap.PathOrDummy},
 				{"Cycle", PTOCycle.PathOrDummy}}},
-			{"AxleConfig", New Dictionary(Of String, Object) From {
+				{"AxleConfig", New Dictionary(Of String, Object) From {
 				{"Type", AxleConfiguration.GetName()},
 				{"Axles", (From axle In Axles Select New Dictionary(Of String, Object) From {
-					{"Inertia", axle.Inertia},
-					{"Wheels", axle.Wheels},
-					{"AxleWeightShare", axle.Share},
-					{"TwinTyres", axle.TwinTire},
-					{"RRCISO", axle.RRC},
-					{"FzISO", axle.FzISO}})}}}
-			}
-
-		json.Content.Add("Body", JToken.FromObject(dic))
+				{"Inertia", axle.Inertia},
+				{"Wheels", axle.Wheels},
+				{"AxleWeightShare", axle.Share},
+				{"TwinTyres", axle.TwinTire},
+				{"RRCISO", axle.RRC},
+				{"FzISO", axle.FzISO}})}}}
+				}
+
+		json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}})
 		Return json.WriteFile(_filePath)
 	End Function
 
diff --git a/VECTO/JSONparser.vb b/VECTO/JSONparser.vb
index 95689356a2..38ae398ee5 100644
--- a/VECTO/JSONparser.vb
+++ b/VECTO/JSONparser.vb
@@ -10,6 +10,7 @@
 ' See the LICENSE.txt for the specific language governing permissions and limitations.
 Imports System.Collections.Generic
 Imports System.IO
+Imports System.Linq
 Imports Microsoft.VisualBasic.FileIO
 Imports Newtonsoft.Json
 Imports Newtonsoft.Json.Linq
@@ -19,7 +20,7 @@ Imports Newtonsoft.Json.Linq
 ''' </summary>
 ''' <remarks></remarks>
 Public Class JSONParser
-	Public Content As JObject 'Dictionary(Of String, Object)
+	Public Content As JToken 'Dictionary(Of String, Object)
 
 	Public Sub New()
 		'Content = New Dictionary(Of String, Object)
@@ -30,50 +31,11 @@ Public Class JSONParser
 			Return False
 		End If
 		Using reader As TextReader = File.OpenText(path)
-			JToken.ReadFrom(New JsonTextReader(reader))
+			Content = JToken.ReadFrom(New JsonTextReader(reader))
 		End Using
 		Return True
 	End Function
 
-	''' <summary>
-	''' Reads a JSON File into the Content variable.
-	''' </summary>
-	''' <param name="path"></param>
-	''' <returns></returns>
-	''' <remarks></remarks>
-	'Public Function ReadFile(path As String) As Boolean
-	'	Dim file As TextFieldParser
-	'	Dim str As String
-
-	'	Content.Clear()
-
-	'	If Not IO.File.Exists(path) Then
-	'		Return False
-	'	End If
-
-	'	Try
-	'		file = New TextFieldParser(path)
-	'	Catch ex As Exception
-	'		Return False
-	'	End Try
-
-	'	If file.EndOfData Then
-	'		file.Close()
-	'		Return False
-	'	End If
-
-	'	str = file.ReadToEnd
-
-	'	file.Close()
-
-	'	Try
-	'		Content = JsonConvert.DeserializeObject(str, Content.GetType)
-	'	Catch ex As Exception
-	'		Return False
-	'	End Try
-
-	'	Return True
-	'End Function
 
 	''' <summary>
 	''' Writes the Content variable into a JSON file.
diff --git a/VECTO/VECTO.vbproj b/VECTO/VECTO.vbproj
index 06c726c5d9..a16a9cae16 100644
--- a/VECTO/VECTO.vbproj
+++ b/VECTO/VECTO.vbproj
@@ -131,6 +131,7 @@
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\packages\iTextSharp.5.5.9\lib\itextsharp.dll</HintPath>
     </Reference>
+    <Reference Include="Microsoft.Build.Framework" />
     <Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
@@ -140,6 +141,7 @@
       <HintPath>..\packages\NLog.4.2.3\lib\net45\NLog.dll</HintPath>
     </Reference>
     <Reference Include="System" />
+    <Reference Include="System.ComponentModel.DataAnnotations" />
     <Reference Include="System.Data" />
     <Reference Include="System.Deployment" />
     <Reference Include="System.Design" />
-- 
GitLab