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

Double quotes problem -> "[\"127.0.0.20\"]" #737

Closed
es1968 opened this issue Feb 17, 2023 · 1 comment
Closed

Double quotes problem -> "[\"127.0.0.20\"]" #737

es1968 opened this issue Feb 17, 2023 · 1 comment

Comments

@es1968
Copy link

es1968 commented Feb 17, 2023

The JSON pair should be like: "ipv4Addresses": ["127.0.0.20"],

I have tried different options but couldn't see the right expected JSON pair

char* vxvcz = "["127.0.0.20"]";
cJSON * ppp = cJSON_CreateString(vxvcz);
// char *out33 = cJSON_Print(ppp);
cJSON_AddItemToObject(data_obj_3, "ipv4Addresses", ppp);

relevant to C in Ubuntu 20.04

Thanks,****

@mbratch
Copy link

mbratch commented Feb 17, 2023

If you want this (as you say your JSON should be like):

"ipv4Address": [ "127.0.0.20" ]

Then the data is an array of one element, so you need a cJSON array object.

If you actually want the brackets to be part of the string (as your title suggests you want), your logic is ok but string constant has an error. Yours is missing the backslash escape for the inner quote characters:

char *vxvcz = "[\"127.0.0.20\"]";

@es1968 es1968 closed this as completed Mar 19, 2023
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