使用RapidJson凝结JSON文件后,如何将输出存储在C 字符串中
how to store output in c++ string after condensing json file using rapidJson
如何将读取器的输出存储在C 字符串中,而不是在stdout
中打印请帮助我找出字符串中的存储输出。
// JSON condenser example
// 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"
#include "rapidjson/filereadstream.h"
#include "rapidjson/filewritestream.h"
#include "rapidjson/error/en.h"
using namespace rapidjson;
int main(int, char*[]) {
// Prepare JSON reader and input stream.
Reader reader;
char readBuffer[65536];
FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
// Prepare JSON writer and output stream.
char writeBuffer[65536];
FileWriteStream os(stdout, writeBuffer,
sizeof(writeBuffer));
Writer<FileWriteStream> writer(os);
// JSON reader parse from the input stream and let writer generate the output.
if (!reader.Parse(is, writer)) {
fprintf(stderr, "nError(%u): %sn", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode()));
return 1;
}
//this should work something like
string str = reader.Parse(is, writer);
//no stdout from reader**
cout<< str <<endl;
//this output will contain json file without whitespaces
return 0;
}
url:http://rapidjson.org/
改编自Rapidjson文档
#include <iostream>
#include <string>
#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
#include "rapidjson/istreamwrapper.h"
#include "rapidjson/ostreamwrapper.h"
using namespace rapidjson;
int main()
{
Document d;
// Read from cin
IStreamWrapper isw(std::cin);
d.ParseStream(isw);
// Write to a char * buffer
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
d.Accept(writer);
// Use the buffer
std::string theJSON(buffer.getString());
// Write to cout
OStreamWrapper osw(std::cout)
d.Accept(osw);
}
相关文章:
- C++:将控制台输出存储在宏中更好吗
- 如何将图像传入C++可执行文件并将输出图像存储在新目录中?
- 如何存储 unicode 字符并将其输出到文件?
- C++:将 std::set_union() 输出存储在 std::multiset 中
- 存储和打印字符,但输出不是预期的
- 如何将函数的输出数据存储在文本文件中
- 我可以将函数的输出参数存储到unique_ptr中吗?
- 将笛卡尔点存储在矢量和输出距离中
- 使用RapidJson凝结JSON文件后,如何将输出存储在C 字符串中
- 如何将预定义数据类型的值存储到数组中并输出它
- 基于C++模板指针的变量会导致返回垃圾,除非之前存储和输出
- 为什么字符串变量"sum"不存储任何数据,程序不给出任何输出
- C++输出流删除存储的数据
- 集合差分的输出可以存储在第一个输入中
- 使用数组,将数据存储在数组中并输出它们
- 使用 QSqlQuery 检索 MySQL 存储过程的输出
- C++:将存储在List容器中的数据输出到文本文件中
- 字符数组输出正确,但实际上没有存储正确的值
- 有没有一种方法可以将阈值运算输出存储在Eigen(C++)中
- 十六进制字符到十进制,并将输出存储为字符