-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Intermittent issues with loadJSON #1484
Comments
Are you sure whether file encoding format is OK (e.g. UTF-8 or ASCII) and the file is not truncated? Also, inspecting the exception message could be helpful. Wrap the |
Pretty sure that the encoding is fine - These files have been good for me previously, including the example I tried. Just to be sure I saved it as a couple of different encodings to try, and I'm not sure if it'd be truncation due to the error I received after putting it in the try/catch block -
With the entire contents of the JSON being from the example site, which I've included just to save a click -
|
I tested this JSON and cannot reproduce this error. Having error at first byte (
If that was not the problem, make sure the file stream is at beginning by checking its current position (should be
Ultimately, you should open the file with a hex editor to make sure there is no extra unexpected hidden bytes at the beginning (e.g. BOM but JSON library could probably handle BOM for UTF8). |
I've confirmed that the file is indeed starting at position 0, and that the file is valid. I've also checked with a hex editor and found no unexpected hidden additional bytes at the beginning. Just to double check, these are the first 16 bytes as show by HxD - Just to double check that no changes had been made to any file, I checked the differences between my included nhlohmann directory and a fresh download, the only difference being in json.hpp with |
The latest stable release is 3.5.0 which you can download from releases page. Nevertheless, older releases shouldn't have any problem in parsing this file. I'm still skeptic if the file can be read correctly since the parser is throwing exception at the very first byte. You might want to try these to dig the issue:
|
It would seem that it's failing to load the file for some reason, but whatever that reason is evades me. |
Any idea how to proceed here? |
I've had a C++ program that's been able to save and load JSON files fine in the past, however recently it's giving a json.exception.parse_error.101, unexpected end of input.
The code which is causing the error is very simple, just
loadJSON("test.json");
Where test.json is stored in the same directory as the program running it. I've also attempted with the absolute path, both return the same error.
I would expect it to load the JSON as expected. Using
std::ifstream ifs("test.json"); json j = json::parse(ifs);
also returns the same error, and just for the hell I tried
std::ifstream my_file("test.json"); json j; j << my_file;
as well. The JSON file is good, it's the first one on JSON.org and I double checked with another parser.
My system is Windows 7, I'm compiling with MinGW version w64.0, with CMake version 3.10.3 on CLion. I'm using the released version rather than the develop branch.
Any help would be appreciated as I'm really not too sure what has caused this out of the blue - I hadn't changed the code which was loading JSON files, yet it broke anyways. If you've any suggestions on how I can clear up my issue to make it easier to solve, I'd be grateful.
The text was updated successfully, but these errors were encountered: