Skip to content

Read Json from File #2139

@llchris

Description

@llchris

Hello, I am cynnad. I am loving so far your json library but i am encourring an issue with my code:

int read_json(const char* p_FilePath, json& p_Json) 
{
	std::ifstream stream;
	stream.open(p_FilePath);
	if(stream.is_open() && !stream.fail())
	{
		stream >> p_Json;
		return 0;
	}

	std::string errorMessage { "Failed to create an inputstream with the file in the path " };
	errorMessage.append(p_FilePath);
	__ERROR__(errorMessage);
	return 1;
}

Using the function:

          json myJsonConfig = {};
	  //Read from file and store into the json
	  if(!read_json("Test.json", myJsonConfig)) return -1;

This is what i came up after reading the wiki. This code seems not to work for me in fact i get a violation error :

Exception thrown at 0x00007FF797F6EF3B in Test.exe: 0xC0000005: access violation while reading the path 0x0000000000000050.

Did I read the json file correctly or did i misunderstand something? Thank you for reading.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions