0

JsonNode 结构:-

{
    "order": [
        "ixtrptdktffr9g3oifhgb9r9mo",
    ],
    "posts": {
        "groqkkwhcbgkmg7nt8tsuf8b3e": {
            "id": "groqkkwhcbgkmg7nt8tsuf8b3e",
            "create_at": 1645604110220,
            "update_at": 1645604110220,
            "edit_at": 0,
            "delete_at": 0,
            "is_pinned": false,
            "user_id": "puehqwuo1pnqpdqwax7r4dkgqh",
            "channel_id": "mjqksfjryp8yim7dk1xxic39jw",
            "root_id": "",
            "original_id": "",
            "message": "46",
            "type": "",
            "props": {
                "disable_group_highlight": true
            },
    },
    "next_post_id": "",
    "prev_post_id": "mz9orcyqhpnappszk4satrws1e"
}

因此,我将有来自 API 调用的具有相同结构的不同 JsonNode 一个一个地添加到主 JsonNode 中,以创建一个具有相同结构的更大 JsonNode,然后对其进行处理。例如:- JsonNodeMain:- 最初是空的,然后是 JsonNode1:- {"order":[id1],"posts":{some posts}} JsonNodeMain=append(JsonNodeMain,JsonNode1) 并且最后我需要 JsonNodeMain 和所有数据。

代码:-

mm_got_history_of_room(MattermostAccount *ma, JsonNode *node, gpointer user_data)
{

    static JsonNode *main_node; //this should be the main json node

    JsonObject *obj = json_node_get_object(node);  //this is the json node with data from api call
    JsonObject *posts = json_object_get_object_member(obj, "posts");
    JsonArray *order = json_object_get_array_member(obj, "order");

    main_node=append(main_node,node); //I want something like this
}

使用递归多次调用此函数并每次获取 JsonNode *node 的不同值。我想将它们附加到静态 jsonNode 中,以便它可以在每次递归调用后保留其值。

4

0 回答 0