json icon indicating copy to clipboard operation
json copied to clipboard

.get<std::string> causing emdash errors

Open poi2000 opened this issue 6 years ago • 4 comments

Not a very experienced programmer, but I've been putting together a small project using json files and encountered some issues with printing values from json. My code contains a number of conditionals similar to below, which are supposed to print out the value associated with a given key in a much larger json file. In this case, "type" is a key with an associated string value. However, when I run the program, the code prints out a small pile of random Unicode symbols instead of what's written in the json file. Is this something that is solvable, or is something wrong on my end?

if (unique.find("type") != unique.end()) { cout << unique["type"].get<std::string>() << endl; }

Expected: Creature — Cat

Actual: Creature ΓÇö Cat

I've been building my code on Windows using Visual Studio 2019 16.3.10, and am currently using nlohmann json version 3.7.3.

Thanks, Julian Lane.

poi2000 avatar Jun 09 '20 01:06 poi2000

How does the JSON value look like? What is the output of unique.dump()?

nlohmann avatar Jun 09 '20 04:06 nlohmann

Hadn't thought about dumping the json values yet, but the dump resulted in the same errors. I attached both the correct text form of the json and the dumped version for further troubleshooting.

unique_dump.txt unique_plaintext_json.txt

poi2000 avatar Jun 09 '20 14:06 poi2000

Both files look good. Please provide the code you use to read/create the value and the exact error message.

nlohmann avatar Jun 09 '20 15:06 nlohmann

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 11 '20 02:07 stale[bot]