If for example I have "all_stations_info": {"1": {"playing": "some song"}, "2": {"playing": "another song"}}
and I want to get the song playing on station "1", how'd I do it without the "1" getting recognized as Int or Float?
typedef doesn't work since it, too, doesn't want an Int, and I'm not sure DynamicAccess can be used with remote data.
If you use haxe.DynamicAccess<Any>
as type then you can just use array access like this all_stations_info["1"]
.
DynamicAccess is an abstract type for working with anonymous structures that are intended to hold collections of objects by the string key. DynamicAccess uses Reflect internally.
var json:{ all_stations_info:haxe.DynamicAccess<Any> } = haxe.Json.parse('{"all_stations_info": {"1": {"playing": "some song"}, "2": {"playing": "another song"}}}');
trace(json.all_stations_info["1"]);
Check: https://try.haxe.org/#2419b
If the type definition is very large, then it is good practice to define it as a typedef:
typedef StationsInfo = { all_stations_info:haxe.DynamicAccess<Any> }
Then you can use var json:StationsInfo = haxe.Json.parse('.....
So, looking at what you posted, if you want it completely typed, then you could define the types like this:
typedef StationsInfo = { all_stations_info:haxe.DynamicAccess<StationData> };
typedef StationData = { playing: String };
Check: https://try.haxe.org/#C6F6d