MCO_RET mco_lJSON_arr_add_str(lews_JSON_context_h json_ctx, const char *value);
json_ctx
lews_JSON_context_t structure.value
This function appends a string value to the current JSON array (e.g., adds
"hockey"as an array element).The function automatically handles JSON escaping of special characters in the
value(such as quotes, backslashes, and control characters) according to RFC 8259.The function may trigger a buffer flush and send data over the network if there is insufficient space in the output buffer to write the formatted string element.
This function can only be called when the current context is inside a JSON array. Attempting to call it at the root level or inside a JSON object will result in an error.
... ret = mco_lJSON_obj_open_arr(&json_ctx, "hobbies"); if (ret == MCO_S_OK) { ret = mco_lJSON_arr_add_str(&json_ctx, "hockey"); if (ret != MCO_S_OK) { printf("mco_lJSON_arr_add_str error %d\n", ret); } ret = mco_lJSON_arr_add_str(&json_ctx, "football"); if (ret != MCO_S_OK) { printf("mco_lJSON_arr_add_str error %d\n", ret); } ret = mco_lJSON_arr_add_str(&json_ctx, "basketball"); if (ret != MCO_S_OK) { printf("mco_lJSON_arr_add_str error %d\n", ret); } ret = mco_lJSON_obj_close(&json_ctx); if (ret != MCO_S_OK) { printf("mco_lJSON_obj_close error %d\n", ret); } } ...
MCO_S_OK
MCO_E_NW_SENDERR
MCO_E_LEWS_PARENT_IS_NOT_ARRAY