-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy path_test_cppjson.cpp
98 lines (88 loc) · 1.78 KB
/
_test_cppjson.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* @file _test_cppjson.cpp
* @brief
*
* @author Yonhgwhan, Roh ([email protected])
* @date 2020/07/20 21:51 created.
* @copyright (C)Somma, Inc. All rights reserved.
**/
#include "stdafx.h"
#include "json/json.h"
bool test_cpp_joson()
{
_mem_check_begin
{
Json::Value root;
FILETIME now; GetSystemTimeAsFileTime(&now);
//
// json ¾²±â
//
root["group_guid"] = "group_guid";
root["host_guid"] = "host_guid";
root["process_guid"] = "process_guid";
root["process_timestamp"] = file_time_to_int(&now);
root["event_id"] = 1500;
root["event_block_key"] = 991827;
root["event_timestamp"] = file_time_to_int(&now);
root["pid"] = 8892;
root["flag"] = 0xff;
root["parent"]["process_guid"] = "process guid";
root["parent"]["process_timestamp"] = file_time_to_int(&now);
//
// array ¾²±â
//
Json::Value ar;
for (int i = 0; i < 8; ++i)
{
ar.append(i);
}
root["array"] = ar;
//
// Json::Value --> string
//
std::stringstream strm;
Json::StreamWriterBuilder f;
try
{
std::unique_ptr<Json::StreamWriter> writer(f.newStreamWriter());
writer->write(root, &strm);
log_info
"%s",
strm.str().c_str()
log_end;
}
catch (std::exception e)
{
log_err
"exception, event id=%s",
root["event_id"].asString().c_str()
log_end;
}
//
// Change Json style
//
f.settings_["commentStyle"] = "None";
f.settings_["indentation"] = "";
{
clear_sstream(strm);
try
{
std::unique_ptr<Json::StreamWriter> writer(f.newStreamWriter());
writer->write(root, &strm);
log_info
"%s",
strm.str().c_str()
log_end;
}
catch (std::exception e)
{
log_err
"exception, event id=%s",
root["event_id"].asString().c_str()
log_end;
}
}
}
_mem_check_end;
return true;
}