Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to open a file #1814

Closed
algaspar opened this issue Oct 26, 2019 · 3 comments
Closed

Trying to open a file #1814

algaspar opened this issue Oct 26, 2019 · 3 comments
Labels
kind: question state: needs more info the author of the issue needs to provide more details

Comments

@algaspar
Copy link

algaspar commented Oct 26, 2019

  • Describe what you want to achieve. I have two json files that I want to read into json objects. Once the files are read in, I want to compare the two objects, and produce a third object (which will be written out to a file) containing the differences.

  • Describe what you tried. I tried the following (abbreviated) code:

json baseJObject;
ifstream inFileJSON(filePath);
inFileJSON >> baseJObject;

It fails on that input, and the program aborts. The Visual Studio decoder says:

Unhandled exception at 0x75581932 in compareScrape.exe: Microsoft C++ exception: nlohmann::detail::parse_error at memory location 0x011FE1C0. occurred

It opens json.hpp to line 4459, which is the JSON_THROW line below:

case 4:
						JSON_THROW(*static_cast<const detail::out_of_range*>(&ex));
						// LCOV_EXCL_START

I also tried "json baseJObject = json::parse(inFileJSON);", but got the same results. I reduced my tests down to very, very small files (see post over on Stack Overflow: https://stackoverflow.com/questions/58566296/opening-a-json-file-giving-fits), but it still fails (please note that the while loop shown there was added for debug purposes. It is not in the actual failing function. I was just checking to see if I could read the file). I've tried to ensure that everything is UTF-8 using Notepad++ and Get-Content in PowerShell (no luck). Cygwin Bash reports the files as UTF-8... If that is the problem, I guess I need to figure out how to programatically ensure that my input files are all UTF-8.

  • Describe which system (OS, compiler) you are using. Visual Studio 2017 Windows 10 Pro

  • Describe which version of the library you are using (release version, develop branch). 3.7.0

This has been very frustrating as the failure seems arbitrary. I've used the same basic syntax in other programs, and it has worked. On the other hand, on a program last week I had this problem and somehow recreating the Visual Studio project and recompiling somehow fixed it (or I got lucky with my input files)

Any suggestions would be greatly appreciated. I guess we could rewrite this in Python, but we were hoping a C++ executable would be more efficient...

Would something like this UTF-8 library solve this issue?

I saw another comment that my code was causing the parser to see EOF and that is what caused the error; so how can I avoid that?

Thanks--

Al

@nlohmann
Copy link
Owner

What is the exact description in the exception? What is the JSON file?

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Oct 27, 2019
@nlohmann
Copy link
Owner

Do you need further assistance with this issue?

@algaspar
Copy link
Author

algaspar commented Nov 16, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question state: needs more info the author of the issue needs to provide more details
Projects
None yet
Development

No branches or pull requests

2 participants