compat.cjson
#includeUltralightweight JSON parser in ANSI C
#include <cJSON.h>
mcpp add compat.cjson@1.7.19
用法
来自本仓库自己的测试项目 —— CI 真的编译并运行过,不是为了网站写的。
// Behavioral test: build a cJSON document, serialize, re-parse, assert fields.
#include <cJSON.h>
#include <cassert>
#include <cstring>
int main() {
cJSON* root = cJSON_CreateObject();
cJSON_AddNumberToObject(root, "answer", 42);
cJSON_AddStringToObject(root, "lib", "cJSON");
char* text = cJSON_PrintUnformatted(root);
cJSON* parsed = cJSON_Parse(text);
assert(parsed != nullptr);
assert(cJSON_GetObjectItem(parsed, "answer")->valueint == 42);
assert(std::strcmp(cJSON_GetObjectItem(parsed, "lib")->valuestring, "cJSON") == 0);
cJSON_free(text);
cJSON_Delete(root);
cJSON_Delete(parsed);
return 0;
}
tests/examples/cjson/tests/parse.cpp · 项目 tests/examples/cjson
构建
- targets
cjson (lib)- language
c++23- C standard
c99- import std
- no
- include dirs
*
特性
| 特性 | 声明了 |
|---|---|
| utils | sources |
源文件 (1)
*/cJSON.c