尝试将cJSON解析器与STM32F103C8T6和KEIL IDE一起使用 问题是,当尝试添加它放弃的第五个元素时,解析器与JSON字符串的最多4个元素的效果非常好。 这段代码似乎没问题:
#include "cJSON.h"
const char * my_json_string =
"{\"device\":\"16\",\"class\":\"master\",\"call\":\"start\",\"ar1\":\"10\"}";
int main (void){
char * device;
char * cls;
char * call;
char * arg1;
cJSON * root = cJSON_Parse(my_json_string);
if (root == NULL){
printf(cJSON_GetErrorPtr());
return 0;
}
cJSON * dev = cJSON_GetObjectItem(root, "device");
cJSON * cla = cJSON_GetObjectItem(root, "class");
cJSON * cl = cJSON_GetObjectItem(root, "call");
cJSON * ar1 = cJSON_GetObjectItem(root, "ar1");
device = dev->valuestring;
cls = cla->valuestring;
call = cl->valuestring;
arg1 = ar1->valuestring;
printf (device);
printf (cls);
printf (call);
printf (arg1);
}
当我将第五对键值添加到字符串
时const char * my_json_string =
"{\"device\":\"16\",\"class\":\"master\",\"call\":\"start\",\"ar1\":\"10\",\"ar2\":\"20\"}";
它会抛出一个错误指针
,"ar2":"20"}
使用NetBeans IDE为桌面编译的相同代码可以正常工作。 这是STM32的RAM映射,我在这里看到没有问题:
Execution Region RW_IRAM1 (Base: 0x20000000, Size: 0x00000ea0, Max: 0x00005000, ABSOLUTE)
Base Addr Size Type Attr Idx E Section Name Object
0x20000000 0x00000014 Data RW 5 .data system_stm32f10x.o
0x20000014 0x00000014 Data RW 18 .data main.o
0x20000028 0x00000008 Data RW 35 .data usart_f10x.o
0x20000030 0x0000000b Data RW 56 .data led_matrix_64x32.o
0x2000003b 0x00000001 PAD
0x2000003c 0x00000004 Data RW 63 .data time_f10x.o
0x20000040 0x00000014 Data RW 155 .data cjson.o
0x20000054 0x00000004 Data RW 357 .data mc_w.l(mvars.o)
0x20000058 0x00000004 Data RW 358 .data mc_w.l(mvars.o)
0x2000005c 0x00000041 Zero RW 34 .bss usart_f10x.o
0x2000009d 0x00000003 PAD
0x200000a0 0x00000800 Zero RW 54 .bss led_matrix_64x32.o
0x200008a0 0x00000200 Zero RW 7 HEAP startup_stm32f10x_md.o
0x20000aa0 0x00000400 Zero RW 6 STACK startup_stm32f10x_md.o
答案 0 :(得分:0)
问题是HEAP尺寸的512 kB太低了。