rapidjson Stream(待更新)

本系列文章以例子的方式进行呈现。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include "rapidjson/rapidjson.h"
#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
#include "rapidjson/filereadstream.h"
#include "cstdio"
using namespace std;
using namespace rapidjson;
int main() {
const char json[] = "[1, 2, 3]";
StringStream s(json);
Document document;
document.ParseStream(s);
for (int i = 0; i < 3; i++)
std::cout << document[i].GetInt() << std::endl;
StringBuffer SB;
Writer<StringBuffer> writer(SB);
document.Accept(writer);
std::cout << SB.GetString() << std::endl;
FILE* fp = fopen("test.json", "rb");
char readBuffer[65535];
FileReadStream is(fp, readBuffer, sizeof(readBuffer));
document.ParseStream(is);
fclose(fp);
for (Value::ConstMemberIterator it = document.MemberBegin();
it != document.MemberEnd(); it++)
std::cout << (it->name).GetString() << std::endl;
}

Comment and share

  • page 1 of 1

魏传柳(2824759538@qq.com)

author.bio


Tencent


ShenZhen,China