File size: 1,290 Bytes
258fb37 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "links.h"
cJSON *ogs_sbi_links_convertToJSON(ogs_sbi_links_t *links)
{
cJSON *root = NULL;
cJSON *object = NULL;
cJSON *linksJSON = NULL;
cJSON *itemsJSON = NULL;
cJSON *selfJSON = NULL;
OpenAPI_lnode_t *node;
ogs_assert(links);
/* _links.items */
itemsJSON = cJSON_CreateArray();
ogs_assert(itemsJSON);
OpenAPI_list_for_each(links->items, node) {
if (!node->data) continue;
object = cJSON_CreateObject();
ogs_assert(object);
cJSON_AddItemToObject(object, "href", cJSON_CreateString(node->data));
cJSON_AddItemToArray(itemsJSON, object);
}
/* _links.self */
selfJSON = cJSON_CreateObject();
ogs_assert(selfJSON);
ogs_assert(links->self);
object = cJSON_CreateString(links->self);
ogs_assert(object);
cJSON_AddItemToObject(selfJSON, "href", object);
/* _links */
linksJSON = cJSON_CreateObject();
ogs_assert(linksJSON);
cJSON_AddItemToObject(linksJSON, "items", itemsJSON);
cJSON_AddItemToObject(linksJSON, "self", selfJSON);
/* root */
root = cJSON_CreateObject();
ogs_assert(root);
cJSON_AddItemToObject(root, "_links", linksJSON);
return root;
}
|