MCO_RET mco_lJSON_obj_open(lews_JSON_context_h json_ctx);
json_ctx
lews_JSON_context_t structure.This function opens a new JSON object as an element of the current JSON array. After this call, all subsequent JSON construction operations (e.g.,
mco_lJSON_obj_add_str,mco_lJSON_obj_add_int) will operate on this newly opened object 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 brace (
{).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 another object will result in an error.
... ret = mco_lJSON_obj_open_arr(&json_ctx, "hobbies"); if (ret == MCO_S_OK) { ret = mco_lJSON_obj_open(&json_ctx); if (ret != MCO_S_OK) { ... } // Add fields to the inner object, e.g.: // mco_lJSON_add_str(&json_ctx, "sport", "hockey"); // mco_lJSON_add_int(&json_ctx, "level", 5); ... 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_JSON_STACK_OVERFLOW
MCO_E_LEWS_PARENT_IS_NOT_ARRAY