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

JSON Parse throwing error #2983

Closed
androbytes opened this issue Aug 29, 2021 · 4 comments
Closed

JSON Parse throwing error #2983

androbytes opened this issue Aug 29, 2021 · 4 comments
Labels
kind: question platform: visual studio related to MSVC solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@androbytes
Copy link

androbytes commented Aug 29, 2021

The JSON Parse is giving an error and I don't know why. I have code in a try-catch and it still throws an error, although I am not sure what line it is on..

        #include "json/json.hpp"
        #include <string>
        #include <stream>
        #include <experimental/filesystem>
        #include <iostream>
        #define CURRENTFILESTRING __FILE__
        
        using json = nlohmann::json;
        
        std::experimental::filesystem::v1::path temppath = CURRENTFILESTRING;
        std::experimental::filesystem::v1::directory_iterator dir( temppath.parent_path() / "Json" );
        int main() {
        for (auto& p : std::experimental::filesystem::directory_iterator(dir)) {
        auto path = p.path().filename();
        std::ifstream comp("Json" / path, std::ifstream::binary);
        //delete &path;
        json compData;
        try {
            compData = json::parse(temppath.parent_path() / "Json" / path);
        }
        catch (json::parse_error& e)
        {
            std::cerr << e.what() << std::endl;
        }
        }
        }

I want it to read the JSON file.

It just throws an error and I have no idea what it means.

  • Compiler: Visual Studio 2019 (ISO C++ 14 Standard)
  • Operating system: Windows 10 Home

the develop branch

Error C2672 'nlohmann::detail::wide_string_input_adapter<nlohmann::detail::iterator_input_adapter<std::experimental::filesystem::v1::_Path_iteratorstd::experimental::filesystem::v1::path>,std::experimental::filesystem::v1::path>::fill_buffer': no matching overloaded function found

It is on line 5651 in json.hpp, I am also using the single-include.

@nlohmann
Copy link
Owner

Can you please share a complete example? There is std::filesystem mentioned which is never included nor makes sense in C++14.

@nlohmann nlohmann added state: needs more info the author of the issue needs to provide more details platform: visual studio related to MSVC labels Aug 29, 2021
@androbytes
Copy link
Author

Is that good enough?

@nlohmann
Copy link
Owner

The parse function assumes to take a std::istream, not just a path, see https://json.nlohmann.me/api/basic_json/parse/

@androbytes
Copy link
Author

Casted it and now it works, thanks!

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation and removed state: needs more info the author of the issue needs to provide more details labels Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question platform: visual studio related to MSVC solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants