MCPcopy Create free account
hub / github.com/acl-dev/acl / do_json

Method do_json

lib_acl_cpp/samples/http_response/main.cpp:144–182  ·  view source on GitHub ↗

���� text/json ����

Source from the content-addressed store, hash-verified

142
143 // ���� text/json ����
144 bool do_json(http_response& res, const char* req_charset, string& err) {
145 json body;
146 if (res.get_body(body, local_charset_) == false) {
147 err += "get_body error";
148 return false;
149 }
150
151 json_node* node = body.first_node();
152 while (node) {
153 if (node->tag_name()) {
154 printf("tag: %s", node->tag_name());
155 if (node->get_text()) {
156 printf(", value: %s\r\n", node->get_text());
157 } else {
158 printf("\r\n");
159 }
160 }
161 node = body.next_node();
162 }
163
164 // ������Ӧͷ�ֶ�
165 http_header& header = res.response_header();
166 string ctype("text/json");
167 if (req_charset) {
168 ctype << "; charset=" << req_charset;
169 header.set_content_type(ctype);
170 } else {
171 header.set_content_type(ctype);
172 }
173
174 printf(">>ctype: %s\r\n", ctype.c_str());
175
176 // ������Ӧ�����ݣ���������Ӧ������
177 string buf;
178 body.build_json(buf);
179
180 // ������Ӧ������
181 return response_body(res, buf, req_charset);
182 }
183
184 bool response_body(http_response& res, const string& body,
185 const char* req_charset) {

Callers

nothing calls this directly

Calls 8

get_textMethod · 0.80
set_content_typeMethod · 0.80
build_jsonMethod · 0.80
get_bodyMethod · 0.45
first_nodeMethod · 0.45
tag_nameMethod · 0.45
next_nodeMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected