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.exception.type_error.304] cannot use at() with object #902

Closed
aprowe opened this issue Jan 5, 2018 · 3 comments
Closed

[json.exception.type_error.304] cannot use at() with object #902

aprowe opened this issue Jan 5, 2018 · 3 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@aprowe
Copy link

aprowe commented Jan 5, 2018

Hi, I am getting

[json.exception.type_error.304] cannot use at() with object

Which doesn't make sense to me, since I figured thats what at() is for.
What does this error mean? Printing my json object it seems to look like a normal json string.

Code:

  std::stringstream ss;

  // msgpack object
  ss << obj;

  std::cout << ss.str();
  // {"subject":"set_detection_mapping_mode", "mode":"3d"}

  std::string str;
  try {
    auto j = json::parse(ss.str().c_str());
    str = j.at('subject').get<std::string>();

  } catch (detail::type_error &e) {
    std::cout << e.what();
    // [json.exception.type_error.304] cannot use at() with object
  }

Thanks

@gregmarr
Copy link
Contributor

gregmarr commented Jan 5, 2018

@aprowe You have .at('subject') (single quotes). You want .at("subject") (double quotes).

You're passing a char which is converting to int, and thus you're trying to array index an object.

@aprowe
Copy link
Author

aprowe commented Jan 5, 2018

Wow. Didn't even know I could use single quotes like that in c++. Thanks!

@gregmarr
Copy link
Contributor

gregmarr commented Jan 5, 2018

It's legal to have multiple characters between the quotes for things like hex escapes and unicode characters, but I'm surprised that your compiler didn't warn you about this.

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Jan 5, 2018
@nlohmann nlohmann closed this as completed Jan 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants