MQTT cJSONS资料
发布日期:2021-05-10 05:07:09 浏览次数:29 分类:精选文章

本文共 3211 字,大约阅读时间需要 10 分钟。

cJSON������������������������������

cJSON������������������������������������������������������������������JSON������������������������cJSON������������������������������������������������

1. ������cJSON���������������������������

������������������������������������������cJSON������������������������������������������������

cJSON *root = cJSON_CreateObject();
cJSON *st = cJSON_CreateObject();
cJSON_AddItemToObject(root, "format", st);
cJSON_AddStringToObject(st, "type", "rect");
cJSON_AddNumberToObject(st, "width", 1920);
cJSON_AddNumberToObject(st, "height", 1080);
cJSON_AddFalseToObject(st, "interlace");
cJSON_AddNumberToObject(st, "frame rate", 24);
char *s = cJSON_Print(root);
if (s) {
printf("%s\n", s);
free(s);
}
if (root)
cJSON_Delete(root);

������������������������������������������������������������������

{
"format": {
"type": "rect",
"width": 1920,
"height": 1080,
"interlace": false,
"frame rate": 24
}
}

���������������������������������������cJSON���������������������������������������������

2. ���������������������������������������

������������cJSON���������������������������������������������������

#include 
#include
#include "cJSON.h"
#include
typedef struct {
char *type;
unsigned int width;
unsigned int height;
unsigned int interlace; // ���������interlace���������������������
unsigned int intrame_rate;
} info;
int main() {
// ������cJSON������
cJSON *root, *formatobj, *typeobj, *heightobj;
root = cJSON_CreateObject();
formatobj = cJSON_AddItemToObject(root, "format");
// ���������������
typeobj = cJSON_AddObjectToObject(formatobj, "type");
cJSON_AddStringToObject(typeobj, "value", "rect");
// ���������������
heightobj = cJSON_AddObjectToObject(formatobj, "height");
cJSON_AddNumberToObject(heightobj, "value", 1920);
// ���������������������
info *info_data = (info *)(malloc(sizeof(info)));
memset(info_data, 0, sizeof(info)); // ���������������
// ���������cJSON������
char *s = cJSON_Print(root);
// ������������
info_data->type = (char *)(malloc(sizeof(char) * strlen(s)+1));
memcpy(info_data->type, s, strlen(s));
printf("���������%s\n", info_data->type);
printf("���������%d\n", info_data->width);
printf("���������%d\n", info_data->height);
printf("������������%d\n", info_data->interlace);
printf("���������%d\n", info_data->intrame_rate);
// ������������
if (s)
free(s);
if (root)
cJSON_Delete(root);
return 0;
}

���������������������������������������������cJSON���������������������������������interlace������������unsigned int���������������atoi������������������������

���������������������������������������������������cJSON������������������������������������������������������������������

������

������������������������������������������������������cJSON������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������cJSON������JSON���������

上一篇:MobaXterm_Personal_12.2软件连接开发板
下一篇:eclipse调试导入带Makefile工程

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2025年04月07日 10时13分33秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章