I want to use a .json file

func load_json(file_path: String):
var error = FileAccess.open(file_path, FileAccess.READ)
if error == null:
print("Failed to open file: ", file_path)
return

var json_string = error.get_as_text()
error.close()

var json = JSON.new()
var parse_result = json.parse(json_string)

if parse_result.error == OK:
json_data = json.result
print("JSON data loaded: ", json_data)
total_images = json_data.assets.size()
print("Total images set to: ", total_images)
else:
print("JSON parse error: ", parse_result.error_string)
The following line of code has encountered this issue againļ¼š
ā€œif parse_result.error == OKā€ :Invalid get index ā€˜errorā€™ (on base: ā€˜intā€™)

Just use parse_result, without the ā€˜.errorā€™:

if parse_result == OK:
...
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.