cJSON can`t parse more than 4 elements

0

Trying to use cJSON parser with STM32F103C8T6 and KEIL IDE The problem is that the parser works pretty well with up to 4 elements of the JSON string, when trying to add the fifth element it gives up. This code seems to be OK:

#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);
}

When I add the fifth pair of key-value to the string

const char * my_json_string = 
        "{\"device\":\"16\",\"class\":\"master\",\"call\":\"start\",\"ar1\":\"10\",\"ar2\":\"20\"}";

it throws an error pointer

,"ar2":"20"}

The same code, compiled with NetBeans IDE for the desktop works fine. Here is the RAM map of the STM32, I see no problems here:

 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
stm32
keil
cjson
asked on Stack Overflow Oct 11, 2017 by Questdoino

1 Answer

0

The problem is that 512 kB for the HEAP size was too low.

answered on Stack Overflow Oct 11, 2017 by Questdoino

User contributions licensed under CC BY-SA 3.0