-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Help for a Beginner? #2141
Comments
If you only need the value at key "text", do this: std::cout << j["text"] << std::endl; If you do not want the quotes (i.e., a serialize JSON value of type string), but a std::string s = j["text"];
std::cout << s << std::endl; |
Fantastic that worked!!! So simple! Thank you for answering. I am slowly understanding the power of json. |
This worked but I tried to do something like this But that does this:
Also is there a better way to do this? allocating memory just to print something without quotation marks doesn't seem ideal |
@nonetrix |
Hello,
I am trying to make a text based game and had the idea to use a json file to store all of the text for each page. And then I can conveniently turn the text into a json object and in my main.cpp output the text from the json file.
Because I am new (barely figured out how to get this library installed) I am having a hell of a time understanding the documentation. Is my stated objective possible?
The only thing I have figured out how to do is store text in a json file:
{
"text": "goes here"
}
and then in my main.cpp file I call that text by opening and reading into the file:
However, this does not behave as I'd expect. It outputs everything including the quotations and the {} which is what I don't want. I would need just a string outputted.
Basically I am very confused.... Any help would be greatly appreciated.
The text was updated successfully, but these errors were encountered: