Skip to content

Implicit conversion causes "cannot use operator[] with a string argument with string" #2098

Description

@tawmoto
  • What is the issue you have?
    I get an exception when I do an implicit conversion and then read a value.
    I read here that json = string should work.

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

using json = nlohmann::json;
string str = R"({"happy": true,"pi": 3.141})";

// if I replace it with "json js = json::parse(str.c_str());", it works!		
json js = str;

// this returns ""[json.exception.type_error.305] cannot use operator[] with a string argument with string"
auto v1 = js["happy"].get<bool>();
  • Which compiler and operating system are you using? Is it a supported compiler?
    VS2017

  • Did you use a released version of the library or the version from the develop branch?
    develop, tried also the latest release and happens also

Maybe I am doing something wrong? I am evaluating this project to replace cjson and I hope that I will make the switch. 👍
Thank you

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    solution: proposed fixa fix for the issue has been proposed and waits for confirmation

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions