
本文共 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���������
发表评论
最新留言
关于作者
