Dictionary help (its confusing)
I turn a json file into a dictionary, how do I get sub data? (Getting "c")
All I can do is dictionary["a"] not dictionary["a"]["b"]
21 Replies
And I'm also struggling with counting?
dictionary["a"].Count doesn't exist but dictionary.Count does?
show code?
if you're turning that json into a dictionary, it would be a
Dictionary<string, Dictionary<string, bool>>
but you probably want a more specifically defined model for your dataAre you sure it's supposed to be a dictionary and not a proper class?
is this about
IConfiguration
?
I only have discord on my phone so I can't see if the syntax worked
jsonLoader
...?
Is it something Godot-specific?The easiest way to know how could you potentially get that value is by debugging that variable
Is
Dictionary
really non-generic?
Or you can just drop a piece of code and disappear
Sure, that's fine tooi have no idea what json library this is
Seeing how it seems to be something that has a non-generic return type, probably some Godot thing
They loooooove their
Variant
typeIs it godot related but csharp
Yeah, but what exactly is this JSON deserialization?
Because the usual way to deserialize JSON would be
not any sort of
new Json()
and casting the result to a non-generic Dictionary
Ah, disappeared again I see
Just so you know, at the pace of you dropping a sentence once every three hours it will be weeks until you get any sort of helpare you trying to load a save file?
I don't know anymore
:SCgetoutofmyhead:
I'm just trying to turn a json to dictionary using csharp because I thought it would look cleaner than a bunch of arrays
You could use the default built in JSON class (it's really great) and then cast it into whatever fits your format
If your JSON file contains more than just what you sent as an example it would actually make sense to create Objects / Classes for each layer
The thing is that I wanted anyone to open it up and easily know what's going on so they could add more to it
The keys makes it really easy to understand what pieces to change
I'm going to try to use the JSON class like you said
i mean people can always go in and change the values, changing the keys however is complicated no matter how you write you code
Serializing/deserializing a class also produces keys btw
Angius
REPL Result: Success
Console Output
Compile: 633.991ms | Execution: 81.985ms | React with ❌ to remove this embed.