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

Build Errors with VS 2019 and json Version 3.9.1 when attempting to replicate SAX Example #2782

Closed
1 of 4 tasks
GoWatcher opened this issue May 23, 2021 · 1 comment
Closed
1 of 4 tasks

Comments

@GoWatcher
Copy link

GoWatcher commented May 23, 2021

I'm getting the following build errors on Microsoft Visual Studio Community 2019
Version 16.9.4 when I attempt to run the SAX Example:

I did the following:

  1. I installed nlohmann.json v3.91 using the NuGet package manager for my project.
  2. When I create a class similar to the sax example from:
    https://nlohmann.github.io/json/api/basic_json/sax_parse/

Can you provide a small but working code example?

#include
#include
#include
#include <nlohmann/json.hpp>

using json = nlohmann::json;

// a simple event consumer that collects string representations of the passed
// values; not inheriting from json::json_sax_t is not required, but can
// help not to forget a required function
class SaxTest : public json::json_sax_t
{
public:
std::vectorstd::string events;

bool null() override
{
    events.push_back("value: null");
    return true;
}

bool boolean(bool val) override
{
    events.push_back("value: " + std::string(val ? "true" : "false"));
    return true;
}

bool number_integer(number_integer_t val) override
{
    events.push_back("value: " + std::to_string(val));
    return true;
}

bool number_unsigned(number_unsigned_t val) override
{
    events.push_back("value: " + std::to_string(val));
    return true;
}

bool number_float(number_float_t val, const string_t& s) override
{
    events.push_back("value: " + s);
    return true;
}

bool string(string_t& val) override
{
    events.push_back("value: " + val);
    return true;
}

bool start_object(std::size_t elements) override
{
    events.push_back("start: object");
    return true;
}

bool end_object() override
{
    events.push_back("end: object");
    return true;
}

bool start_array(std::size_t elements) override
{
    events.push_back("start: array");
    return true;
}

bool end_array() override
{
    events.push_back("end: array");
    return true;
}

bool key(string_t& val) override
{
    events.push_back("key: " + val);
    return true;
}

bool binary(json::binary_t& val) override
{
    events.push_back("binary");
    return true;
}

bool parse_error(std::size_t position, const std::string& last_token, const json::exception& ex) override
{
    events.push_back("error: " + std::string(ex.what()));
    return false;
}

};

What is the expected behavior?

And what is the actual behavior instead?

Which compiler and operating system are you using?

  • Compiler: Microsoft Visual Studio Community 2019, Version 16.9.4

  • Operating system: Windows 10 Latest updates

Which version of the library did you use?

  • [ X] latest release version 3.9.1
  • other release - please state the version: ___
  • the develop branch

If you experience a compilation error: can you compile and run the unit tests?

  • yes
  • no - please copy/paste the error message below
    Severity Code Description Project File Line Suppression State

Error C2665 'nlohmann::detail::input_adapter': none of the 3 overloads could convert all the argument types WinVis C:\Users\johnsojo\source\repos\CorSI\packages\nlohmann.json.3.9.1\build\native\include\nlohmann\json.hpp 23966
Error C3536 'ia': cannot be used before it is initialized WinVis C:\Users\johnsojo\source\repos\CorSI\packages\nlohmann.json.3.9.1\build\native\include\nlohmann\json.hpp 23968
Error C2825 'InputAdapterType': must be a class or namespace when followed by '::' WinVis C:\Users\johnsojo\source\repos\CorSI\packages\nlohmann.json.3.9.1\build\native\include\nlohmann\json.hpp 6532
...

@GoWatcher
Copy link
Author

I found issue in my code. I change:
bool result = json::sax_parse(sDataString, &SaxTest);
to
bool result = json::sax_parse(sDataString.GetString(), &SaxTest););

sDataString is defined as a CString and sax_parse() doesn't have a template to support CString but it does the type string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant