MCO_RET mco_lJSON_arr_open(lews_JSON_context_h json_ctx);
json_ctx
lews_JSON_context_t structure.This function opens a new nested JSON array as an element of the current JSON array. After this call, all subsequent JSON construction operations (e.g.,
mco_lJSON_arr_add_str,mco_lJSON_arr_add_int) will operate on this newly opened inner array until it is closed withmco_lJSON_obj_close().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 opening bracket (
[).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, "nested_arrays"); if (ret == MCO_S_OK) { // First inner array ret = mco_lJSON_arr_open(&json_ctx); if (ret == MCO_S_OK) { mco_lJSON_arr_add_str(&json_ctx, "item1"); mco_lJSON_arr_add_str(&json_ctx, "item2"); mco_lJSON_obj_close(&json_ctx); // close inner array } // Second inner array ret = mco_lJSON_arr_open(&json_ctx); if (ret == MCO_S_OK) { mco_lJSON_arr_add_int(&json_ctx, 100); mco_lJSON_arr_add_int(&json_ctx, 200); mco_lJSON_obj_close(&json_ctx); // close inner array } mco_lJSON_obj_close(&json_ctx); // close "nested_arrays" } ...
MCO_S_OK
MCO_E_NW_SENDERR
[).MCO_E_LEWS_JSON_STACK_OVERFLOW
MCO_E_LEWS_PARENT_IS_NOT_ARRAY