2019-07-27 22:44:32 +08:00
|
|
|
|
#include "lib_acl.h"
|
2015-09-27 20:59:21 +08:00
|
|
|
|
|
|
|
|
|
#define STR acl_vstring_str
|
|
|
|
|
|
|
|
|
|
static const char* default_data = \
|
|
|
|
|
"{ 'menu name': {\r\n"
|
|
|
|
|
" 'id:file': 'file',\r\n"
|
|
|
|
|
" 'value{': 'File',\r\n"
|
|
|
|
|
" 'popup{}': {\r\n"
|
|
|
|
|
" 'menuitem1}': [\r\n"
|
2019-07-21 20:08:51 +08:00
|
|
|
|
" {'value': 'New1', 'onclick': 'CreateNewDoc()'},\r\n"
|
|
|
|
|
" {'value': 'Open1', 'onclick': 'OpenDoc()'},\r\n"
|
|
|
|
|
" {'value': 'Close1', 'onclick': 'CloseDoc()'}\r\n"
|
2015-09-27 20:59:21 +08:00
|
|
|
|
" ],\r\n"
|
|
|
|
|
" 'menuname[]': 'hello world',\r\n"
|
2019-07-21 20:08:51 +08:00
|
|
|
|
" 'inner': { 'value' : 'new2 ', 'value' : 'open2' },\r\n"
|
2015-09-27 20:59:21 +08:00
|
|
|
|
" 'menuitem2': [\r\n"
|
2019-07-21 20:08:51 +08:00
|
|
|
|
" {'value': 'New3', 'onclick': 'CreateNewDoc()'},\r\n"
|
|
|
|
|
" {'value': 'Open3', 'onclick': 'OpenDoc()'},\r\n"
|
|
|
|
|
" {'value': 'Close3', 'onclick': 'CloseDoc()'},\r\n"
|
|
|
|
|
" {{'value': 'Help3', 'onclick': 'Help()'}}"
|
2015-09-27 20:59:21 +08:00
|
|
|
|
" ]\r\n"
|
|
|
|
|
" }\r\n"
|
|
|
|
|
" }\r\n,"
|
|
|
|
|
" 'help': 'hello world!',\r\n"
|
|
|
|
|
" 'menuitem2': [\r\n"
|
2019-07-21 20:08:51 +08:00
|
|
|
|
" {'value': 'New4', 'onclick': 'CreateNewDoc()'},\r\n"
|
|
|
|
|
" {'value': 'Open4', 'onclick': 'OpenDoc()'},\r\n"
|
|
|
|
|
" {'value': 'Close4', 'onclick': 'CloseDoc()'},\r\n"
|
|
|
|
|
" [{'value': 'Save4', 'onclick': 'SaveDoc()'}]"
|
2015-09-27 20:59:21 +08:00
|
|
|
|
" ]\r\n"
|
|
|
|
|
"}\r\n"
|
|
|
|
|
"{ 'hello world' }\r\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void test_json(void)
|
|
|
|
|
{
|
|
|
|
|
ACL_JSON *json = acl_json_alloc();
|
|
|
|
|
const char* ptr = default_data;
|
2019-07-21 11:47:59 +08:00
|
|
|
|
ACL_VSTRING *buf = acl_vstring_alloc(1024);
|
2015-09-27 20:59:21 +08:00
|
|
|
|
|
|
|
|
|
ptr = acl_json_update(json, ptr);
|
2019-07-21 20:08:51 +08:00
|
|
|
|
|
|
|
|
|
printf("-------------------------------------------------------\r\n");
|
2015-09-27 20:59:21 +08:00
|
|
|
|
printf("finish: %s, left char: %s\r\n",
|
|
|
|
|
acl_json_finish(json) ? "yes" : "no", ptr);
|
2019-07-21 20:08:51 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
2019-07-21 11:47:59 +08:00
|
|
|
|
|
|
|
|
|
acl_json_build(json, buf);
|
2015-09-27 20:59:21 +08:00
|
|
|
|
acl_json_free(json);
|
2019-07-21 11:47:59 +08:00
|
|
|
|
acl_vstring_free(buf);
|
2015-09-27 20:59:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
|
test_json();
|
|
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
getchar();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|