static void parse_json(const char *data) { ACL_JSON *json = acl_json_alloc(); ACL_VSTRING *buf1 = acl_vstring_alloc(128); ACL_VSTRING *buf2 = acl_vstring_alloc(128); ACL_ARRAY *nodes; const char *tag = "header"; printf("buf src: %s\r\n", data); printf("------------------------------------------------\r\n"); acl_json_update(json, data); acl_json_build(json, buf1); printf("result src: %s\r\n", STR(buf1)); printf("------------------------------------------------\r\n"); nodes = acl_json_getElementsByTagName(json, tag); if (nodes == NULL) { printf("not found tag: %s\r\n", tag); acl_vstring_free(buf1); acl_vstring_free(buf2); acl_json_free(json); return; } printf(">>>tag: %s, len: %d\r\n", tag, acl_array_size(nodes)); ACL_ITER iter; #define STR acl_vstring_str #define LEN ACL_VSTRING_LEN acl_foreach(iter, nodes) { ACL_JSON_NODE *node = (ACL_JSON_NODE*) iter.data; ACL_JSON_NODE *tag_node = node->tag_node; if (tag_node == NULL) continue; printf(">>>tag: %s\r\n", STR(node->ltag)); ACL_ITER iter2; acl_foreach(iter2, tag_node) { ACL_JSON_NODE *node1 = (ACL_JSON_NODE*) iter2.data; if (node1->ltag == NULL || LEN(node1->ltag) == 0) continue; printf(">>>child tag: %s, txt: %s\r\n", STR(node1->ltag), node1->text ? STR(node1->text) : "null"); }
const std::vector<json_node*>& json::getElementsByTagName(const char* tag) const { const_cast<json*>(this)->clear(); ACL_ARRAY* a = acl_json_getElementsByTagName(json_, tag); if (a == NULL) return nodes_query_; ACL_ITER iter; acl_foreach(iter, a) { ACL_JSON_NODE *tmp = (ACL_JSON_NODE*) iter.data; json_node* node = NEW json_node(tmp, const_cast<json*>(this)); const_cast<json*>(this)->nodes_query_.push_back(node); }