forked from bytedance/sonic-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathat_pointer.cpp
More file actions
49 lines (40 loc) · 1.01 KB
/
Copy pathat_pointer.cpp
File metadata and controls
49 lines (40 loc) · 1.01 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <string>
#include "sonic/sonic.h"
using PointerType = sonic_json::GenericJsonPointer<sonic_json::StringView>;
int main() {
std::string json = R"(
{
"a":1,
"b":[
{"a":1},
{"b":2}
]
}
)";
sonic_json::Document doc;
if (doc.Parse(json).HasParseError()) {
std::cout << "Parse failed!\n";
return -1;
}
sonic_json::Node* node1 = doc.AtPointer(PointerType({"a"}));
if (node1 != nullptr) {
std::cout << "/a exists!\n";
} else {
std::cout << "/a doesn't exist!\n";
}
sonic_json::Node* node2 = doc.AtPointer(PointerType({"b", 1, "a"}));
if (node2 != nullptr) {
std::cout << "/b/1/a Eixsts!\n";
} else {
std::cout << "/b/1/a doesn't exist!\n";
}
sonic_json::Node* node3 = doc.AtPointer("b", 1, "b");
if (node3 != nullptr) {
std::cout << "/b/1/b Eixsts!\n";
} else {
std::cout << "/b/1/b doesn't exist!\n";
}
return 0;
}
// g++ -I../include/ -march=haswell --std=c++11 at_pointer.cpp -o at_pointer