armink / struct2json

A fast convert library between the JSON and C structure. Implement structure serialization and deserialization for C. | C 结构体与 JSON 快速互转库,快速实现 C 结构体的序列化及反序列化
MIT License
680 stars 293 forks source link

cJSON_Print 返回的指针地址为NULL #7

Closed xiaodingding closed 5 years ago

xiaodingding commented 6 years ago

经实际使用于STM32F107中,cJSON_Print 返回的指针地址为NULL,请问这个是什么原因?

代码如下: static Student orignal_student_obj = { .id = 24, .weight = 71.2, .score = {1, 2, 3, 4, 5, 6, 7, 8}, .name = "armink", .hometown.name = "China", };

cJSON *json_send = struct_to_json(&orignal_student_obj);

//cJSON *json_send = struct_to_json(&send_struct);

ptr = cJSON_Print(json_send);
armink commented 6 years ago

标准库的 动态内存管理 api 实现了吗?

需要用到 malloc/free 的

xiaodingding commented 6 years ago

使用的是默认的malloc/free

xiaodingding commented 6 years ago

使用的编辑器是Keil

armink commented 6 years ago

那应该是内存不足,或者你的动态内存初始化就没有做好。

自己先写个简单的 malloc/free 验证下吧。

xiaodingding commented 5 years ago

I have solved this problem. Thank you

xiaodingding commented 5 years ago

I have solved this problem. Thank you