Godot Version | v-4.2.1 stable
Hello !
I’m new to Godot and I’m developping an app that needs an online database. For this I’m using JSON coupled with the HTTPRequest in Godot. I followed tutorials and always have the same issue. The response = 0 and it returns "Invalid get index ‘question’ (on base :‘int’).
Here’s my GDScript code :
extends Node
func _button_pressed(button):
$HTTPRequest.request(url)
func _on_http_request_completed(result, response_code, headers, body):
var json = JSON.new()
var response = json.parse(body.get_string_from_utf8())
print(response)
if response["question"].has("Abracadabra"):
print("YES")
else:
print("NO")
And here’s what my JSON look like :
{"enigmas" :[
{
"answer": "8",
"fakeAnswer1": "5",
"fakeAnswer2": "3",
"fakeAnswer3": "88",
"id": 1,
"question": "Abracadabra",
"solution": "Godot is fire but I hate JSON"
}
]
My goal here is to get the console print “YES”.
Every kind of help is welcome !
Thanks a lot !