pretty.cpp 1019 B

123456789101112131415161718192021222324252627282930
  1. // JSON pretty formatting example
  2. // This example can only handle UTF-8. For handling other encodings, see prettyauto example.
  3. #include "rapidjson/reader.h"
  4. #include "rapidjson/prettywriter.h"
  5. #include "rapidjson/filereadstream.h"
  6. #include "rapidjson/filewritestream.h"
  7. #include "rapidjson/error/en.h"
  8. using namespace rapidjson;
  9. int main(int, char*[]) {
  10. // Prepare reader and input stream.
  11. Reader reader;
  12. char readBuffer[65536];
  13. FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
  14. // Prepare writer and output stream.
  15. char writeBuffer[65536];
  16. FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
  17. PrettyWriter<FileWriteStream> writer(os);
  18. // JSON reader parse from the input stream and let writer generate the output.
  19. if (!reader.Parse<kParseValidateEncodingFlag>(is, writer)) {
  20. fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode()));
  21. return 1;
  22. }
  23. return 0;
  24. }