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

I know the library supports UTF-8, but failed to dump the value #1036

Closed
htonus opened this issue Apr 3, 2018 · 6 comments
Closed

I know the library supports UTF-8, but failed to dump the value #1036

htonus opened this issue Apr 3, 2018 · 6 comments
Labels

Comments

@htonus
Copy link

htonus commented Apr 3, 2018

Bug Report

  • What is the issue you have?
    Failed to dump object with UTF8 value;

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?
    jsonObject["name"] = "Telefónica";
    jsonObject.dump()

  • What is the expected behavior?
    stringified json

  • And what is the actual behavior instead?
    thrown an exeption. Is it possible to avoid exceptions?

  • Which compiler and operating system are you using? Is it a supported compiler?
    VS 2017 Community edition

  • Did you use a released version of the library or the version from the develop branch?
    From dev branch

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

Feature Request

  • Describe the feature in as much detail as possible.

  • Include sample usage where appropriate.

@nlohmann nlohmann added the platform: visual studio related to MSVC label Apr 3, 2018
@nlohmann
Copy link
Owner

nlohmann commented Apr 3, 2018

  • Can you make sure that MSVC is actually using UTF-8 for string literals?
  • What exactly does the exception say?

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Apr 3, 2018
@htonus
Copy link
Author

htonus commented Apr 3, 2018

it is multibyte, and exception happened here:
case UTF8_REJECT: // decode found invalid UTF-8 byte
{
std::stringstream ss;
ss << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << static_cast(byte);
JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + ss.str()));
}
screen shot 2018-04-03 at 3 09 17 pm

@nlohmann
Copy link
Owner

nlohmann commented Apr 3, 2018

If it is multibyte, then it is not UTF-8.

@htonus
Copy link
Author

htonus commented Apr 3, 2018

How I can convert to the format json::dump would accept it please?

@nlohmann
Copy link
Owner

nlohmann commented Apr 3, 2018

This is currently not possible. The library only supports UTF-8 at the moment. Maybe this helps: https://docs.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8

@nlohmann nlohmann removed the state: needs more info the author of the issue needs to provide more details label Apr 3, 2018
@htonus
Copy link
Author

htonus commented Apr 3, 2018

Okay, thank you for the answers.

@htonus htonus closed this as completed Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants