MCO_RET mco_lJSON_obj_open_obj(lews_JSON_context_h json_ctx, const char *key);
json_ctx
lews_JSON_context_t structure.key
This function adds a new nested JSON object as a member of the current JSON object, using the specified
keyas its name (e.g.,"address": { ... }). 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 inner 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 key and opening brace (
"key":{).This function can only be called when the current context is inside a JSON object. Attempting to call it at the root level or inside an array will result in an error.
... ret = mco_lJSON_obj_open_obj(&json_ctx, "address"); if (ret == MCO_S_OK) { ret = mco_lJSON_obj_add_str(&json_ctx, "street", "Main Street"); if (ret != MCO_S_OK) { printf("mco_lJSON_obj_add_str error %d\n", ret); } ret = mco_lJSON_obj_add_str(&json_ctx, "city", "New York"); if (ret != MCO_S_OK) { printf("mco_lJSON_obj_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_JSON_STACK_OVERFLOW
MCO_E_LEWS_PARENT_IS_NOT_OBJECT