Closed Diego-Hernandez-Moodys closed 3 months ago
You can use yyjson_arr_size(arr)
to get the size of an array, yyjson_get_len(str)
to get the length of a string.
And then I would use strdup to transfer the memory, right?
int num_hits = yyjson_arr_size(items_array);
char** outs = calloc(num_hits + 1, sizeof(char*));
yyjson_arr_foreach(items_array, ix, max, item)
{
const char* out = yyjson_get_str(item);
outs[i] = strdup(out); // Copy each string
}
Yes, this works if you want to manage the strings yourself.
Thanks, you may close unless you have another suggestion.
I'd like some help in extracting the non-object arrays.
I have a json like this and would like to store the "metadata" field to a char**
I can malloc and then iterate through the array, but I don't know how many values there are ahead of time, do I?