0 votes

I'm creating a 4 Pics 1 Word-like game, now I'm having problems on how to show the images in TextureRect that stored in my JSON file. Here's the format of my json file.

{
"1": {
    "gold" : 5,
    "pictures" : [ "res://icon.png", "res://icon1.png", "res://icon2.png", "res://icon3.png" ],
    "letters" : [ "T", "E", "S", "T" ]
},
"2": {
    "gold" : 5,
    "pictures" : [ "res://icon.png", "res://icon1.png", "res://icon2.png", "res://icon3.png" ],
    "letters" : [ "B", "E", "S", "T" ]
},
"3": {
    "gold" : 5,
    "pictures" : [ "res://icon.png", "res://icon1.png", "res://icon2.png", "res://icon3.png" ],
    "letters" : [ "W", "E", "S", "T" ]
}
}
in Engine by (21 points)

1 Answer

0 votes

Something like this?

# Load the JSON file
var f := File.new()
f.open("res://my_json.json",File.READ)
var json_text := f.get_as_text()
var json_data:Dictionary = JSON.parse(json_text).result
f.close()

# Print out the image set array for the specific ID
print(json_data["1"].pictures)

It's hard to tell what exactly you want with a vague question

by (58 points)

Hi, thank you for your reply, I got this error:

Invalid get index 'pictures' (on base: 'Dictionary').

What does print(json_data) show?`

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.