Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | kitfox |
I’m porting something I originally wrote using GDScript to c#. I’m trying to figure out how to get a Dictionary from JSONParseResult.Result. I’m calling JSON.Parse() from inside a method and I want the method to return a dictionary of the data loaded.
The data appears to be there since I can see it in the debugger - however, I cannot seem cast it to a Dictionary object. I’ve tried casting JSONParseResult.Result to Dictionary<object, object> and Dictionary<string, object>, but each time it just results in null.
How I I return a dictionary from this method?
private Dictionary<object, object> parseTileMetadata()
{
HexMap map = new HexMap();
File f = new File();
f.Open(_tileMeta, File.ModeFlags.Read);
JSONParseResult res = JSON.Parse(f.GetAsText());
var data = res.Result;
f.Close();
var foo = res.Result as Dictionary<object, object>;
return foo;
}
I know, this probably doesn’t quite answer your question, but I stumbled on it yesterday and it also treats JSON, dictionaries and getting data into a Godot project. Maybe it shows an alternative.
ChristianSF | 2020-08-02 06:39
https://www.youtube.com/watch?v=g_7hgbxjtLY
Landroval | 2023-02-12 16:26