EasyJSON Casting Error

Working with Easy JSON and I have run into a problem, I have a complex json structure (not my fault, I don’t control it.). Working entirely in JS for compatibility issues with another asset I am using later on.

I receive this error:

InvalidCastException: Unable to cast <{"flight":[{"actual_blocks_time":"04/08/2015 07:07:00",
"actual_time":"04/08/2015 07:10:00",
"aircraft_type":"320",
"alternate_remark_one":"Landed",
"alternate_remark_two":"Landed",
"airline":"JQ",
"codeshare_airlines":["QF"],
"codeshare_flights":["QF5701"],
"estimated_time":"04/08/2015 07:10:00",
"flight_number":"JQ701",
"leg":"A",
"locations":["Melbourne"],
"operational_date":"04/08/2015",
"primary_remark":"Landed",
"scheduled_time":"04/08/2015 07:15:00",
"terminal":"1","trip_number":0}]}> (with type = System.Collections.Generic.Dictionary`2[System.String,EasyJSON.fsData]) to type System.Collections.Generic.List`1[EasyJSON.fsData]
    EasyJSON.fsData.Cast[List`1] ()
    EasyJSON.fsData.get_AsList ()
    EasyJSON.Internal.fsIEnumerableConverter.TryDeserialize (EasyJSON.fsData data, System.Object& instance, System.Type storageType)
    EasyJSON.fsSerializer.InternalDeserialize_4_Converter (EasyJSON.fsData data, System.Type resultType, System.Object& result)
    EasyJSON.fsSerializer.InternalDeserialize_4_Cycles (EasyJSON.fsData data, System.Type resultType, System.Object& result)
    EasyJSON.fsSerializer.InternalDeserialize_3_Inheritance (EasyJSON.fsData data, System.Type storageType, System.Object& result)
    EasyJSON.fsSerializer.InternalDeserialize_2_Version (EasyJSON.fsData data, System.Type storageType, System.Object& result)
    EasyJSON.fsSerializer.InternalDeserialize_1_CycleReference (EasyJSON.fsData data, System.Type storageType, System.Object& result)
    EasyJSON.fsSerializer.TryDeserialize (EasyJSON.fsData data, System.Type storageType, System.Object& result)
    EasyJSON.Internal.fsReflectedConverter.TryDeserialize (EasyJSON.fsData data, System.Object& instance, System.Type storageType)
    EasyJSON.fsSerializer.InternalDeserialize_4_Converter (EasyJSON.fsData data, System.Type resultType, System.Object& result)
    EasyJSON.fsSerializer.InternalDeserialize_4_Cycles (EasyJSON.fsData data, System.Type resultType, System.Object& result)
    EasyJSON.fsSerializer.InternalDeserialize_3_Inheritance (EasyJSON.fsData data, System.Type storageType, System.Object& result)
    EasyJSON.fsSerializer.InternalDeserialize_2_Version (EasyJSON.fsData data, System.Type storageType, System.Object& result)
    EasyJSON.fsSerializer.InternalDeserialize_1_CycleReference (EasyJSON.fsData data, System.Type storageType, System.Object& result)
    EasyJSON.fsSerializer.TryDeserialize (EasyJSON.fsData data, System.Type storageType, System.Object& result)
    EasyJSON.Internal.fsReflectedConverter.TryDeserialize (EasyJSON.fsData data, System.Object& instance, System.Type storageType)
    EasyJSON.fsSerializer.InternalDeserialize_4_Converter (EasyJSON.fsData data, System.Type resultType, System.Object& result)
    EasyJSON.fsSerializer.InternalDeserialize_4_Cycles (EasyJSON.fsData data, System.Type resultType, System.Object& result)
    EasyJSON.fsSerializer.InternalDeserialize_3_Inheritance (EasyJSON.fsData data, System.Type storageType, System.Object& result)
    EasyJSON.fsSerializer.InternalDeserialize_2_Version (EasyJSON.fsData data, System.Type storageType, System.Object& result)
    EasyJSON.fsSerializer.InternalDeserialize_1_CycleReference (EasyJSON.fsData data, System.Type storageType, System.Object& result)
    EasyJSON.fsSerializer.TryDeserialize (EasyJSON.fsData data, System.Type storageType, System.Object& result)
    EasyJSON.fsSerializer.TryDeserialize[FlightRoot] (EasyJSON.fsData data, .FlightRoot& instance)
    EasyJSON.Serializer.Deserialize[FlightRoot] (System.String json)
    FIDSLoader.GetLatestFile () (at Assets/FIDSLoader.js:76)
    FIDSLoader.Start () (at Assets/FIDSLoader.js:20)

I have tried a variety of solutions however none seem to work.

My codebase is very small so I will add it here.

#pragma strict

import System.DateTime;
import System.IO;
import System.Collections.Generic;
import EasyJSON;

public var path:String = "C:\\fids\\";
private var output:String = "";
public var dates:List.<double> = new List.<double>();
public var filenames:List.<String> = new List.<String>();
public var timer:float = 0;
public var check_interval:float = 3200;
public var ui:UIControl;
public var flightdata:FlightRoot;

function Start ()
{
	//path.Replace('\\', Path.DirectorySeparatorChar); //for multi-OS compatibility only. Not required right now
	GetLatestFile();
	ui.PromtUpdate();
}

function Update ()
{
	if(timer >= check_interval)
	{
		GetLatestFile();
		ui.PromtUpdate();
		timer = 0;
	}
	else
	{
		timer+=Time.deltaTime;
	}
}

function GetLatestFile()
{
	try
	{
		var info = new DirectoryInfo(path);
		var fileInfo = info.GetFiles();
		var nojson:boolean = true;
		
		if(fileInfo.Length > 0)
		{
			for(var file in fileInfo)
			{
				if(file.Extension)
				{
					if(file.Extension.Equals(".json"))
					{
						filenames.Add(file.Name);
						dates.Add(DateTimeToUnixTimestamp(file.CreationTime));
						nojson = false;
					}
				}
				else
				{
					nojson = false;
				}
				
			}
			
			if(nojson)
			{
				Debug.Log("No Valid data file");
			}
			else
			{
				//find the laest and load it!!
				var filename:String = filenames[GetNewestPosition()];
				output = System.IO.File.ReadAllText(path+filename);
				//convert to a json file
				flightdata = new Serializer.Deserialize.<FlightRoot>(output);
				
				//delete all except latest. 
				for(var oldfile in fileInfo)
				{
					if(oldfile.Extension)
					{
						if(oldfile.Extension.Equals(".json"))
						{
							if(!oldfile.Name.Equals(filename))
							{
								//baweted!
								System.IO.File.Delete(path+oldfile.Name);
							}
						}
					}
				}
				
				//clear arrays
				dates.Clear();
				filenames.Clear();
				
			}
		}
		else
		{
			Debug.Log("No Valid data file");
		}
	}
	catch(e:DirectoryNotFoundException)
	{
		Debug.Log("Invalid Directory, check directory settings");
	}
}

public function GetNewestPosition():int
{
	var highest:double = 0;
	var highestpos:int = 0;
	var currentpos:int = 0;
	
	for(var date in dates)
	{
		if(date >= highest)
		{
			highestpos = currentpos;
		}
		currentpos++;
	}
	
	return highestpos;
}

public function GetData():FlightRoot
{
	return flightdata;
}

public static function DateTimeToUnixTimestamp(dateTime:System.DateTime):double 
{
    return (dateTime - new System.DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds;
}

public class FlightRoot
{
	var flight_set:FlightSet;
}

import System.Collections.Generic;

public class FlightSet
{
	var airport:String;
	var date:String;
	var flights:List.<Flight>;
	var time_window:String;
}

import System.Collections.Generic;

public class Flight
{
	var actual_blocks_time:String;
	var actual_time:String;
	var aircraft_type:int;
	var alternate_remark_one:String;
	var alternate_remark_two:String;
	var airline:String;
	var codeshare_airlines:List.<String>;
	var codeshare_flights:List.<String>;
	var estimated_time:String;
	var flight_number:String;
	var leg:String;
	var locations:List.<String>;
	var operational_date:String;
	var primary_remark:String;
	var scheduled_time:String;
	var terminal:int;
	var trip_number:int;
}

If the json snippet is the whole file, it is not a valid json

  "locations":"Melbourne"],

should be

   "locations":["Melbourne"],

Copy paste your snippet into some json validator like jsonlint and it will let you know that it is wrong there.

The issue with locations is just something the formatting here has done, it happened when I used the code tag around it, it also tried to turn a lot of " into ’ ’ . the json is fine in reality.

Reposting the error here without the formatting issues it had in my OP

InvalidCastException: Unable to cast <{“flight”:[{“actual_blocks_time”:“04/08/2015 07:07:00”,“actual_time”:“04/08/2015 07:10:00”,“aircraft_type”:“320”,“alternate_remark_one”:“Landed”,“alternate_remark_two”:“Landed”,“airline”:“JQ”,“codeshare_airlines”:[“QF”],“codeshare_flights”:[“QF5701”],“estimated_time”:“04/08/2015 07:10:00”,“flight_number”:“JQ701”,“leg”:“A”,“locations”:[“Melbourne”],“operational_date”:“04/08/2015”,“primary_remark”:“Landed”,“scheduled_time”:“04/08/2015 07:15:00”,“terminal”:“1”,“trip_number”:0}]}> (with type = System.Collections.Generic.Dictionary2[System.String,EasyJSON.fsData]) to type System.Collections.Generic.List1[EasyJSON.fsData]
EasyJSON.fsData.Cast[List`1] ()
EasyJSON.fsData.get_AsList ()
EasyJSON.Internal.fsIEnumerableConverter.TryDeserialize (EasyJSON.fsData data, System.Object& instance, System.Type storageType)
EasyJSON.fsSerializer.InternalDeserialize_4_Converter (EasyJSON.fsData data, System.Type resultType, System.Object& result)
EasyJSON.fsSerializer.InternalDeserialize_4_Cycles (EasyJSON.fsData data, System.Type resultType, System.Object& result)
EasyJSON.fsSerializer.InternalDeserialize_3_Inheritance (EasyJSON.fsData data, System.Type storageType, System.Object& result)
EasyJSON.fsSerializer.InternalDeserialize_2_Version (EasyJSON.fsData data, System.Type storageType, System.Object& result)
EasyJSON.fsSerializer.InternalDeserialize_1_CycleReference (EasyJSON.fsData data, System.Type storageType, System.Object& result)
EasyJSON.fsSerializer.TryDeserialize (EasyJSON.fsData data, System.Type storageType, System.Object& result)
EasyJSON.Internal.fsReflectedConverter.TryDeserialize (EasyJSON.fsData data, System.Object& instance, System.Type storageType)
EasyJSON.fsSerializer.InternalDeserialize_4_Converter (EasyJSON.fsData data, System.Type resultType, System.Object& result)
EasyJSON.fsSerializer.InternalDeserialize_4_Cycles (EasyJSON.fsData data, System.Type resultType, System.Object& result)
EasyJSON.fsSerializer.InternalDeserialize_3_Inheritance (EasyJSON.fsData data, System.Type storageType, System.Object& result)
EasyJSON.fsSerializer.InternalDeserialize_2_Version (EasyJSON.fsData data, System.Type storageType, System.Object& result)
EasyJSON.fsSerializer.InternalDeserialize_1_CycleReference (EasyJSON.fsData data, System.Type storageType, System.Object& result)
EasyJSON.fsSerializer.TryDeserialize (EasyJSON.fsData data, System.Type storageType, System.Object& result)
EasyJSON.Internal.fsReflectedConverter.TryDeserialize (EasyJSON.fsData data, System.Object& instance, System.Type storageType)
EasyJSON.fsSerializer.InternalDeserialize_4_Converter (EasyJSON.fsData data, System.Type resultType, System.Object& result)
EasyJSON.fsSerializer.InternalDeserialize_4_Cycles (EasyJSON.fsData data, System.Type resultType, System.Object& result)
EasyJSON.fsSerializer.InternalDeserialize_3_Inheritance (EasyJSON.fsData data, System.Type storageType, System.Object& result)
EasyJSON.fsSerializer.InternalDeserialize_2_Version (EasyJSON.fsData data, System.Type storageType, System.Object& result)
EasyJSON.fsSerializer.InternalDeserialize_1_CycleReference (EasyJSON.fsData data, System.Type storageType, System.Object& result)
EasyJSON.fsSerializer.TryDeserialize (EasyJSON.fsData data, System.Type storageType, System.Object& result)
EasyJSON.fsSerializer.TryDeserialize[FlightRoot] (EasyJSON.fsData data, .FlightRoot& instance)
EasyJSON.Serializer.Deserialize[FlightRoot] (System.String json)
FIDSLoader.GetLatestFile () (at Assets/FIDSLoader.js:76)
FIDSLoader.Start () (at Assets/FIDSLoader.js:20)