JSONFX, Reading JSON Object

Hi,

I suppose this question is for people who have actually worked with JSonFX. I’ve downloaded a version of JSonFX specific to unity: here

From what I understand… you create a class the inherits from an interface (JsonConverter), which will convert the json dictionary into an object using the overridden ReadJson() function. I’ve created two classes that convert the passed dictionary into a C# class object. Both converter class look basically the same, but will return different types of objects, but for some reason the ReadJson function is only being called on one Converter class, and not the other.

Does anyone know of a reason why this would be happening? I have been mucking with this all day, and I can’t find a reason as to why the ReadJson() func of one class is called and not the other. Both CanConvert() funcs return true and then false because it calls CanConvert on the type, then on the dictionary for some reason, but that’s besides the point, which is that BOTH CanConvert() functions return true, then false, BUT afterwords ClassA’s ReadJson() is called, but ClassB’s ReadJson() wont be called.

I hope I haven’t confused you guys too much.

Also, side question, is there a way to only grab the Dictionary of the json object?

Thank you in advance for any help.

I know a lot about JsonFx but not a lot about the changes made for the Unity fork. The JsonConverter stuff is new as JsonFx is supposed to be able to figure out the types and automatically do the type coercion itself (this is much improved in v2 rather than v1 which is what the Unity fork is from).

Just specify the type in JsonReader.Deserialize(Type) to tell it do do type coercion. To get a dictionary instead of coercing to a type, don’t specify a type (this is the default).

That being said, did you tell the reader about the converter via JsonReaderSettings.AddTypeConverter(JsonConverter)? It probably knows about one via C#'s type inference, but not the other.