2015-04-03 12:58:23 +08:00
|
|
|
// JSON condenser example
|
2011-11-18 17:01:23 +00:00
|
|
|
|
|
|
|
// This example parses JSON text from stdin with validation,
|
|
|
|
// and re-output the JSON content to stdout without whitespace.
|
|
|
|
|
|
|
|
#include "rapidjson/reader.h"
|
|
|
|
#include "rapidjson/writer.h"
|
2011-11-21 10:00:33 +00:00
|
|
|
#include "rapidjson/filereadstream.h"
|
|
|
|
#include "rapidjson/filewritestream.h"
|
2014-06-27 01:53:56 +08:00
|
|
|
#include "rapidjson/error/en.h"
|
2011-11-18 17:01:23 +00:00
|
|
|
|
|
|
|
using namespace rapidjson;
|
|
|
|
|
2012-11-16 13:02:05 +00:00
|
|
|
int main(int, char*[]) {
|
2014-08-11 22:26:45 +08:00
|
|
|
// Prepare JSON reader and input stream.
|
|
|
|
Reader reader;
|
|
|
|
char readBuffer[65536];
|
|
|
|
FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
|
2011-11-18 17:01:23 +00:00
|
|
|
|
2014-08-11 22:26:45 +08:00
|
|
|
// Prepare JSON writer and output stream.
|
|
|
|
char writeBuffer[65536];
|
|
|
|
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
|
|
|
|
Writer<FileWriteStream> writer(os);
|
2011-11-18 17:01:23 +00:00
|
|
|
|
2014-08-11 22:26:45 +08:00
|
|
|
// JSON reader parse from the input stream and let writer generate the output.
|
|
|
|
if (!reader.Parse(is, writer)) {
|
|
|
|
fprintf(stderr, "\nError(%u): %s\n", (unsigned)reader.GetErrorOffset(), GetParseError_En(reader.GetParseErrorCode()));
|
|
|
|
return 1;
|
|
|
|
}
|
2011-11-18 17:01:23 +00:00
|
|
|
|
2014-08-11 22:26:45 +08:00
|
|
|
return 0;
|
2011-11-18 17:01:23 +00:00
|
|
|
}
|