I am trying to make a simple system that can retrieve dialogue from a json file, but nothing I can find online seems to work.
The error I currently have, is that the json is retrieved as a string, yet I cannot find a way to retireve it as an array.
A large amount of dialogue will be retrieved eventually, so it needs to put it in an array
The current retrieval method I have is the following:
var FILE_PATH = "res://Assets/Dialogue/test_dialogue.json"
func _ready():
var json = JSON.new()
var file = FileAccess.open(FILE_PATH, FileAccess.READ)
var json_text = JSON.stringify(file.get_as_text())
file.close()
var error = json.parse(json_text)
if error == OK:
var data_received = json.data
if typeof(data_received) == TYPE_ARRAY:
# process code here
pass
This code retrieves the json, but on typeof(data_recieved) it returns a type of a string.
How do I make it return an array?
My json looks ike this currently:
{
"dialouge": [
{
"type" : "line","text" : "dialogue line 1","char" : "talker","expression" : "1"
},
{
"type" : "line","text" : "dialogue line 2","char" : "talker","expression" : "1"
},
{
"type" : "line","text" : "dialogue line 3","char" : "talker","expression" : "1"
},
{
"type" : "line","text" : "dialogue line 4","char" : "talker","expression" : "1"
},
{
"type" : "line","text" : "dialogue line 5, the very very very long line of dialogue that is soooooooooo long it barely fits on screen","char" : "talker","expression" : "1"
}
]
}