mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-14 17:00:52 +08:00
45 lines
1.0 KiB
C++
45 lines
1.0 KiB
C++
|
#include "stdafx.h"
|
|||
|
/**
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>json<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⣬\t \n<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
|
|||
|
int main()
|
|||
|
{
|
|||
|
const char* type = "set";
|
|||
|
const char* tablename = "\txmailuser";
|
|||
|
const char* name = " chenzhen";
|
|||
|
|
|||
|
printf(">>>>{%s}\r\n", tablename);
|
|||
|
acl::json json;
|
|||
|
acl::json_node& root = json.get_root().add_child(false, true);
|
|||
|
root.add_child("type", type);
|
|||
|
root.add_child("tablename", tablename);
|
|||
|
root.add_child("name", name);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>json<6F>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
printf("json to string:%s\r\n", json.to_string().c_str());
|
|||
|
|
|||
|
acl::string buf;
|
|||
|
json.build_json(buf);
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><C9B5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ֵ
|
|||
|
acl::json json2(buf.c_str());
|
|||
|
acl::json_node* root2 = json2.get_root().first_child();
|
|||
|
acl::json_node* child = root2->first_child();
|
|||
|
|
|||
|
const char* tag, *txt;
|
|||
|
while (child != NULL)
|
|||
|
{
|
|||
|
if ((tag = child->tag_name()) != NULL && *tag != 0
|
|||
|
&& (txt = child->get_text()) != NULL && *txt != 0)
|
|||
|
{
|
|||
|
printf("tag: %s, txt: %s\n", tag, txt);
|
|||
|
}
|
|||
|
else
|
|||
|
printf("no tag name or no txt in json node");
|
|||
|
|
|||
|
child = root2->next_child();
|
|||
|
}
|
|||
|
printf("\r\n");
|
|||
|
return 0;
|
|||
|
}
|