-
-
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
How to save json to file? #690
Comments
This code works for me: #include "json.hpp"
#include <fstream>
using jsonf = nlohmann::json;
int main() {
jsonf jsonfile;
jsonfile["foo"] = "bar";
std::ofstream file("key.json");
file << jsonfile;
} |
Sorry, replace: const unsigned char a[] = "testing";
jsonfile["foo"] = a; |
This works for me with the latest version of the #include "json.hpp"
#include <fstream>
using jsonf = nlohmann::json;
int main() {
jsonf jsonfile;
const unsigned char a[] = "testing";
jsonfile["foo"] = a;
std::ofstream file("key.json");
file << jsonfile;
} Note the output is {"foo":[116,101,115,116,105,110,103,0]} Use |
Strange... I will see what can I do. |
Are you using the latest release? If so, it is likely that this is fixed on develop |
I guess thats fixed somehow, but now i get this error:
|
String are stored as std::string key = jsonfilekey["key"]; and organize the conversion to |
Related: #683 |
For unknown reasons, that corrupts the whole string. |
What do you mean with "corrupts". Can you provide an example? |
Any news on this? |
@NeverMine17 Any news on this? |
file.flush(); |
I'm trying to save json to file and all I'm getting is some weird errors. Any help?
Here is all the info:
Verison json: 2.1.1
gcc version 6.3.0 20170618 (Ubuntu 6.3.0-19ubuntu1)
Example code
Error
The text was updated successfully, but these errors were encountered: