I'm trying to get a list of all the item names from a JSON file in res://, which are formatted as an Array containing a dictionary, containing a dictionary of key value pairs of the names in different languages (Picture is attached). When I use print(json_as_dict[i]) it will print all the correct info. When I use print(json_as_dict[i]["LocalizedNames]) it will print all the correct info. When i use print(json_as_dict[i]["LocalizedNames"]["EN-US"]) it gives the error.
Full code:
extends OptionButton
func _ready():
var file = "res://Assets/items/items.json"
var json_as_text = FileAccess.get_file_as_string(file)
var json_as_dict = JSON.parse_string(json_as_text)
traverse_array(json_as_dict)
func traverse_array(json_as_dict):
if json_as_dict:
for i in range(0, json_as_dict.size()):
//print(json_as_dict[i]) #Working
//print(json_as_dict[i]["LocalizedNames"] #Working
print(json_as_dict[i]["LocalizedNames"]["EN-US"]) //#Not working
I've tried a lot of stuff but I can't seem to figure out why it's not working even after some research and help in the beginner chat.