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

Function main

example/get_and_set.cpp:30–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30int main() {
31 std::string json = R"(
32 {
33 "a": 1,
34 "b": 2
35 }
36 )";
37
38 sonic_json::Document doc;
39 doc.Parse(json);
40
41 if (doc.HasParseError()) {
42 std::cout << "Parse failed!\n";
43 return -1;
44 }
45
46 // Find member by key
47 if (!doc.IsObject()) { // Check JSON value type.
48 std::cout << "Incorrect doc type!\n";
49 return -1;
50 }
51 auto m = doc.FindMember("a");
52 if (m != doc.MemberEnd()) {
53 std::cout << "Before Setting new value:\n";
54 print_member(m);
55 std::cout << "After Setting value:\n";
56 set_new_value(m);
57 print_member(m);
58 } else {
59 std::cout << "Find key doesn't exist!\n";
60 }
61 return 0;
62}
63// g++ -I../include/ -march=haswell --std=c++11 get_and_set.cpp -o get_and_set

Callers

nothing calls this directly

Calls 6

print_memberFunction · 0.85
set_new_valueFunction · 0.85
ParseMethod · 0.80
HasParseErrorMethod · 0.80
IsObjectMethod · 0.80
FindMemberMethod · 0.80

Tested by

no test coverage detected