Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cJSON_Print return NULL #45

Open
kormilicinkostia opened this issue Mar 13, 2020 · 2 comments
Open

cJSON_Print return NULL #45

kormilicinkostia opened this issue Mar 13, 2020 · 2 comments

Comments

@kormilicinkostia
Copy link

kormilicinkostia commented Mar 13, 2020

Good afternoon.
I am using cJSON v1.7.12. I am trying to create a json of the form:
{ "status":"text", "num": 123 }

For this, I use the following code:
`
cJSON *monitor = cJSON_CreateObject();
if (monitor == NULL)
{
cJSON_Delete(monitor);
ESP_LOGE(TAG, "Error create json");
}
cJSON *status = cJSON_CreateString("text");

if (status == NULL)
{
cJSON_Delete(monitor);
ESP_LOGE(TAG, "Error create status");
}

cJSON_AddItemToObject(monitor, "status", status);
int k = 123;
cJSON *num = cJSON_CreateNumber(k);
ESP_LOGI(TAG, "End cJSON_CreateNumber");
if (num == NULL)
{
    cJSON_Delete(monitor);
    ESP_LOGE(TAG, "Error create num");
}

cJSON_AddItemToObject(monitor, "num", num);
ESP_LOGI(TAG, "End cJSON_AddItemToObject");
char* resp_str = cJSON_PrintUnformatted(monitor);
ESP_LOGI(TAG, "End cJSON_Print");
ESP_LOGI(TAG, "out_json: \n '%s'", resp_str);

`

I found that if cJSON_CreateNumber is in my code, then the cJSON_Print function returns null. What is the reason for this problem?

@kbranigan
Copy link
Owner

perhaps try with the source repository https://github.com/DaveGamble/cJSON
maybe this has been fixed or produces a different result.

@kormilicinkostia
Copy link
Author

At the last commit in the wizard (e8077d01500279a7b45b8cd7a0ae94ea7ad5748a) this problem was not resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants