MCPcopy Create free account
hub / github.com/bytedance/sonic-cpp / main

Function main

example/at_pointer.cpp:8–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6using PointerType = sonic_json::GenericJsonPointer<sonic_json::StringView>;
7
8int main() {
9 std::string json = R"(
10 {
11 "a":1,
12 "b":[
13 {"a":1},
14 {"b":2}
15 ]
16 }
17 )";
18
19 sonic_json::Document doc;
20 if (doc.Parse(json).HasParseError()) {
21 std::cout << "Parse failed!\n";
22 return -1;
23 }
24
25 sonic_json::Node* node1 = doc.AtPointer(PointerType({"a"}));
26 if (node1 != nullptr) {
27 std::cout << "/a exists!\n";
28 } else {
29 std::cout << "/a doesn't exist!\n";
30 }
31
32 sonic_json::Node* node2 = doc.AtPointer(PointerType({"b", 1, "a"}));
33 if (node2 != nullptr) {
34 std::cout << "/b/1/a Eixsts!\n";
35 } else {
36 std::cout << "/b/1/a doesn't exist!\n";
37 }
38
39 sonic_json::Node* node3 = doc.AtPointer("b", 1, "b");
40 if (node3 != nullptr) {
41 std::cout << "/b/1/b Eixsts!\n";
42 } else {
43 std::cout << "/b/1/b doesn't exist!\n";
44 }
45
46 return 0;
47}
48
49// g++ -I../include/ -march=haswell --std=c++11 at_pointer.cpp -o at_pointer

Callers

nothing calls this directly

Calls 2

HasParseErrorMethod · 0.80
ParseMethod · 0.80

Tested by

no test coverage detected