static const char *json_element(ACL_JSON *json, const char *data) { /* 创建数组成员对象 */ ACL_JSON_NODE *element; SKIP_SPACE(data); if (*data == 0) return NULL; if (*data == '{') { data++; json->status = ACL_JSON_S_OBJ; return data; } else if (*data == '[') { data++; json->status = ACL_JSON_S_ARRAY; return data; } element = acl_json_node_alloc(json); element->type = ACL_JSON_T_ELEMENT; element->depth = json->curr_node->depth + 1; if (element->depth > json->depth) json->depth = element->depth; acl_json_node_add_child(json->curr_node, element); /* 将该数组成员对象置为当前 JSON 分析结点 */ json->curr_node = element; json->status = ACL_JSON_S_VALUE; return data; }
static const char *json_obj(ACL_JSON *json, const char *data) { ACL_JSON_NODE *obj; SKIP_SPACE(data); if (*data == 0) return NULL; /* 创建对象 '{}' 子结点 */ obj = acl_json_node_alloc(json); obj->type = ACL_JSON_T_OBJ; obj->depth = json->curr_node->depth + 1; if (obj->depth > json->depth) json->depth = obj->depth; /* 根据 json 结点对象前缀的不同,记录不同的对象后缀 */ obj->left_ch = '{'; obj->right_ch = '}'; acl_json_node_add_child(json->curr_node, obj); if (LEN(json->curr_node->ltag) > 0) json->curr_node->tag_node = obj; json->curr_node = obj; json->status = ACL_JSON_S_MEMBER; return data; }
static const char *json_array(ACL_JSON *json, const char *data) { ACL_JSON_NODE *array; SKIP_SPACE(data); if (*data == 0) return NULL; /* 创建数组对象 */ array = acl_json_node_alloc(json); array->left_ch = '['; array->right_ch = ']'; array->type = ACL_JSON_T_ARRAY; array->depth = json->curr_node->depth + 1; if (array->depth > json->depth) json->depth = array->depth; acl_json_node_add_child(json->curr_node, array); if (LEN(json->curr_node->ltag) > 0) json->curr_node->tag_node = array; json->curr_node = array; json->status = ACL_JSON_S_ELEMENT; return data; }
json_node& json_node::add_child(json_node* child, bool return_child /* = false */) { ACL_JSON_NODE* node = child->get_json_node(); // 先添加 child 至父节点中 acl_json_node_add_child(node_me_, node); child->parent_ = this; if (return_child) return *child; return *this; }
static const char *json_member(ACL_JSON *json, const char *data) { /* 创建上面所建对象结点的成员对象 */ ACL_JSON_NODE *member = acl_json_node_alloc(json); member->type = ACL_JSON_T_MEMBER; member->depth = json->curr_node->depth + 1; if (member->depth > json->depth) json->depth = member->depth; acl_json_node_add_child(json->curr_node, member); /* 将该成员对象置为当前 JSON 分析结点 */ json->curr_node = member; json->status = ACL_JSON_S_PAIR; return data; }