throws an exception

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By VarionDrakon

throws the current code into an exception:

	private string JSONLoadName;
void TestJSON()
{
		var TestJson = new Godot.File();
		TestJson.Open("JsonFiles/Test.json", File.ModeFlags.Read);
		string dataText = TestJson.GetAsText();
		JSONParseResult result = JSON.Parse(dataText);
		Godot.Collections.Dictionary scenario = result.Result as Godot.Collections.Dictionary;

	try
	{
		JSONLoadName = scenario["Name"] as string;
		GD.Print($"Debug {JSONLoadName}");
	}
	catch
	{
		GD.Print("Error JSON File!");
	}
		TestJson.Close();
}

JSON file code:

null = {
"Name": "Ivan",
}

What are your ideas for solving the error?

Does your filepath have to be prepended by user:// or res://? What is the exception say? Have you confirmed you’re loading the file and getting content?

beaverusiv | 2021-04-04 02:57

Do you think this is the case? The fact is that in a simpler, but similar method, I downloaded and read a regular TXT file.

VarionDrakon | 2021-04-04 03:03

Thank you very much, helped res://

VarionDrakon | 2021-04-04 03:07

If this has solved it please mark my answer as correct, and have fun :slight_smile:

beaverusiv | 2021-04-04 03:11

Yes, but you wrote in a comment, not as an answer)

VarionDrakon | 2021-04-04 03:15

I added an answer

beaverusiv | 2021-04-04 03:17

:bust_in_silhouette: Reply From: beaverusiv

Does your filepath have to be prepended by user:// or res://?