mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-04-21 08:18:57 +02:00

Rewerite and revert some code that this library can be built in pre-C++11 and C++11 env. Main Change List: 1. using -> typedef 2. not using auto & decltype 3. not using raw string literals 4. ..., other c++11 features will be chosen to compile, depending on env.
35 lines
808 B
C++
35 lines
808 B
C++
#include "json/json.h"
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
/** \brief Write a Value object to a string.
|
|
* Example Usage:
|
|
* $g++ stringWrite.cpp -ljsoncpp -std=c++11 -o stringWrite
|
|
* $./stringWrite
|
|
* {
|
|
* "action" : "run",
|
|
* "data" :
|
|
* {
|
|
* "number" : 1
|
|
* }
|
|
* }
|
|
*/
|
|
int main() {
|
|
Json::Value root;
|
|
Json::Value data;
|
|
JSONCPP_CONST bool shouldUseOldWay = false;
|
|
root["action"] = "run";
|
|
data["number"] = 1;
|
|
root["data"] = data;
|
|
|
|
if (shouldUseOldWay) {
|
|
Json::FastWriter writer;
|
|
const std::string json_file = writer.write(root);
|
|
std::cout << json_file << std::endl;
|
|
} else {
|
|
Json::StreamWriterBuilder builder;
|
|
const std::string json_file = Json::writeString(builder, root);
|
|
std::cout << json_file << std::endl;
|
|
}
|
|
return EXIT_SUCCESS;
|
|
}
|