mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-29 18:37:41 +08:00
modify json sample
This commit is contained in:
parent
cb92a8ccf2
commit
926b0f2c71
@ -8,26 +8,26 @@ static const char* default_data = \
|
||||
" 'value{': 'File',\r\n"
|
||||
" 'popup{}': {\r\n"
|
||||
" 'menuitem1}': [\r\n"
|
||||
" {'value': 'New', 'onclick': 'CreateNewDoc()'},\r\n"
|
||||
" {'value': 'Open', 'onclick': 'OpenDoc()'},\r\n"
|
||||
" {'value': 'Close', 'onclick': 'CloseDoc()'}\r\n"
|
||||
" {'value': 'New1', 'onclick': 'CreateNewDoc()'},\r\n"
|
||||
" {'value': 'Open1', 'onclick': 'OpenDoc()'},\r\n"
|
||||
" {'value': 'Close1', 'onclick': 'CloseDoc()'}\r\n"
|
||||
" ],\r\n"
|
||||
" 'menuname[]': 'hello world',\r\n"
|
||||
" 'inner': { 'value' : 'new ', 'value' : 'open' },\r\n"
|
||||
" 'inner': { 'value' : 'new2 ', 'value' : 'open2' },\r\n"
|
||||
" 'menuitem2': [\r\n"
|
||||
" {'value': 'New', 'onclick': 'CreateNewDoc()'},\r\n"
|
||||
" {'value': 'Open', 'onclick': 'OpenDoc()'},\r\n"
|
||||
" {'value': 'Close', 'onclick': 'CloseDoc()'},\r\n"
|
||||
" {{'value': 'Help', 'onclick': 'Help()'}}"
|
||||
" {'value': 'New3', 'onclick': 'CreateNewDoc()'},\r\n"
|
||||
" {'value': 'Open3', 'onclick': 'OpenDoc()'},\r\n"
|
||||
" {'value': 'Close3', 'onclick': 'CloseDoc()'},\r\n"
|
||||
" {{'value': 'Help3', 'onclick': 'Help()'}}"
|
||||
" ]\r\n"
|
||||
" }\r\n"
|
||||
" }\r\n,"
|
||||
" 'help': 'hello world!',\r\n"
|
||||
" 'menuitem2': [\r\n"
|
||||
" {'value': 'New', 'onclick': 'CreateNewDoc()'},\r\n"
|
||||
" {'value': 'Open', 'onclick': 'OpenDoc()'},\r\n"
|
||||
" {'value': 'Close', 'onclick': 'CloseDoc()'},\r\n"
|
||||
" [{'value': 'Save', 'onclick': 'SaveDoc()'}]"
|
||||
" {'value': 'New4', 'onclick': 'CreateNewDoc()'},\r\n"
|
||||
" {'value': 'Open4', 'onclick': 'OpenDoc()'},\r\n"
|
||||
" {'value': 'Close4', 'onclick': 'CloseDoc()'},\r\n"
|
||||
" [{'value': 'Save4', 'onclick': 'SaveDoc()'}]"
|
||||
" ]\r\n"
|
||||
"}\r\n"
|
||||
"{ 'hello world' }\r\n";
|
||||
@ -40,14 +40,32 @@ static void test_json(void)
|
||||
ACL_VSTRING *buf = acl_vstring_alloc(1024);
|
||||
|
||||
ptr = acl_json_update(json, ptr);
|
||||
|
||||
printf("-------------------------------------------------------\r\n");
|
||||
printf("finish: %s, left char: %s\r\n",
|
||||
acl_json_finish(json) ? "yes" : "no", ptr);
|
||||
printf("-------------------------------------------------------\r\n");
|
||||
printf("\r\n%s\r\n", default_data);
|
||||
printf("-------------------------------------------------------\r\n");
|
||||
printf("\r\n%s\r\n", acl_vstring_str(buf));
|
||||
printf("-------------------------------------------------------\r\n");
|
||||
|
||||
ACL_ARRAY *a = acl_json_getElementsByTags(json, "menuitem2/value");
|
||||
if (a) {
|
||||
ACL_ITER iter;
|
||||
|
||||
acl_foreach(iter, a) {
|
||||
ACL_JSON_NODE* node = (ACL_JSON_NODE*) iter.data;
|
||||
printf("tag=%s, value=%s\r\n",
|
||||
acl_vstring_str(node->ltag),
|
||||
acl_vstring_str(node->text));
|
||||
}
|
||||
|
||||
acl_json_free_array(a);
|
||||
}
|
||||
|
||||
acl_json_build(json, buf);
|
||||
acl_json_free(json);
|
||||
|
||||
printf("\r\n%s\r\n", default_data);
|
||||
printf("\r\n%s\r\n", acl_vstring_str(buf));
|
||||
acl_vstring_free(buf);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user