This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Issue with "cJSON_Parse failed :" in lte_ble_gateway application

Hi Team,

We are working on the nRF9160 DK. We are integrating the central_uart code into the lte_ble_gateway, As we integrated for the purpose to use NUS(nordic uart service). As the project is compiled successfully, But at run time i observed the below issue in the LTE link monitor

Please find the issue in the highlighted region

Please let me know that do i missed any configs or please point me to the solution why this issue arises

Thanks,

venkatesh

Parents
  • Could you debug your application and look at the function 

    • cJSON_Parse() (<..>\ncs\v1.3.0\nrf\subsys\net\lib\nrf_cloud\src\nrf_cloud_codec.c)
      • cJSON_ParseWithOpts() (<..>\ncs\v1.3.0\nrf\ext\cjson\cJSON.c):


    CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated)
    {
        parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
        cJSON *item = NULL;
    
        /* reset error position */
        global_error.json = NULL;
        global_error.position = 0;
    
        if (value == NULL)
        {
            goto fail;
        }
    
        buffer.content = (const unsigned char*)value;
        buffer.length = strlen((const char*)value) + sizeof("");
        buffer.offset = 0;
        buffer.hooks = global_hooks;
    
        item = cJSON_New_Item(&global_hooks);
        if (item == NULL) /* memory fail */
        {
            goto fail;
        }
    
        if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer))))
        {
            /* parse failure. ep is set. */
            goto fail;
        }
    
        /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */
        if (require_null_terminated)
        {
            buffer_skip_whitespace(&buffer);
            if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0')
            {
                goto fail;
            }
        }
        if (return_parse_end)
        {
            *return_parse_end = (const char*)buffer_at_offset(&buffer);
        }
    
        return item;
    
    fail:
        if (item != NULL)
        {
            cJSON_Delete(item);
        }
    
        if (value != NULL)
        {
            error local_error;
            local_error.json = (const unsigned char*)value;
            local_error.position = 0;
    
            if (buffer.offset < buffer.length)
            {
                local_error.position = buffer.offset;
            }
            else if (buffer.length > 0)
            {
                local_error.position = buffer.length - 1;
            }
    
            if (return_parse_end != NULL)
            {
                *return_parse_end = (const char*)local_error.json + local_error.position;
            }
    
            global_error = local_error;
        }
    
        return NULL;
    }

    Put breakpoints on all "goto fail" to see where the error comes from.

    Best regards,

    Simon

Reply
  • Could you debug your application and look at the function 

    • cJSON_Parse() (<..>\ncs\v1.3.0\nrf\subsys\net\lib\nrf_cloud\src\nrf_cloud_codec.c)
      • cJSON_ParseWithOpts() (<..>\ncs\v1.3.0\nrf\ext\cjson\cJSON.c):


    CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated)
    {
        parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
        cJSON *item = NULL;
    
        /* reset error position */
        global_error.json = NULL;
        global_error.position = 0;
    
        if (value == NULL)
        {
            goto fail;
        }
    
        buffer.content = (const unsigned char*)value;
        buffer.length = strlen((const char*)value) + sizeof("");
        buffer.offset = 0;
        buffer.hooks = global_hooks;
    
        item = cJSON_New_Item(&global_hooks);
        if (item == NULL) /* memory fail */
        {
            goto fail;
        }
    
        if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer))))
        {
            /* parse failure. ep is set. */
            goto fail;
        }
    
        /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */
        if (require_null_terminated)
        {
            buffer_skip_whitespace(&buffer);
            if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0')
            {
                goto fail;
            }
        }
        if (return_parse_end)
        {
            *return_parse_end = (const char*)buffer_at_offset(&buffer);
        }
    
        return item;
    
    fail:
        if (item != NULL)
        {
            cJSON_Delete(item);
        }
    
        if (value != NULL)
        {
            error local_error;
            local_error.json = (const unsigned char*)value;
            local_error.position = 0;
    
            if (buffer.offset < buffer.length)
            {
                local_error.position = buffer.offset;
            }
            else if (buffer.length > 0)
            {
                local_error.position = buffer.length - 1;
            }
    
            if (return_parse_end != NULL)
            {
                *return_parse_end = (const char*)local_error.json + local_error.position;
            }
    
            global_error = local_error;
        }
    
        return NULL;
    }

    Put breakpoints on all "goto fail" to see where the error comes from.

    Best regards,

    Simon

Children
No Data
Related