- #include <iostream>
-
-
-
- #include "json_reader.cpp"
- #include "json_value.cpp"
- #include "json_writer.cpp"
-
- using namespace std;
- using namespace Json;
-
- int main(int argc, char *argv[])
- {
-
-
- char *config_doc=" { \"encoding\" :\"UTF-8\",\"plug-ins\" : [\"python\",\"c++\",\"ruby\"],\"indent\" : { \"length\" : 3, \"use_space\": true }}";
-
- Json::Value root;
- Json::Reader reader;
- bool parsingSuccessful = reader.parse( config_doc, root );
- if ( !parsingSuccessful )
- {
-
- std::cout << "Failed to parse configuration\n"
- << reader.getFormattedErrorMessages();
- return 1;
- }
-
- reader.parse(config_doc,root,false);
-
- std::string encoding = root.get("encoding", "GBK" ).asString();
- const Json::Value plugins = root["plug-ins"];
-
- for(int index = 0; index < plugins.size(); ++index ){
- cout<<plugins[index];
- }
-
- cout<< plugins;
- cout<<encoding<<endl;
-
- root["encoding"] = "GB2312";
- root["indent"]["length"] = 5;
- root["indent"]["use_space"] = false;
-
- Json::StyledWriter writer;
-
- std::string outputConfig = writer.write( root );
-
- cout<<outputConfig;
-
- system("PAUSE");
- return 0;
- }