MCO_RET mco_lJSON_ctx_close(lews_JSON_context_h json_ctx);
json_ctx
lews_JSON_context_t structure.This function closes the root JSON object by appending a closing brace (
}) to the output buffer.It does not automatically flush or send the data to the client. However, if there is insufficient space in the output buffer to write the closing brace, the function will first flush the current buffer contents to the network, clear the buffer, and then write the
}character.Before writing the closing brace, the function verifies that all nested JSON objects and arrays have been properly closed. If the internal structure counter is not zero, it returns an error indicating unmatched brackets or braces.
After calling this function, the application should explicitly call
mco_lews_flush()to ensure all remaining data is sent to the client.lews_JSON_context_t json_ctx; ... // Respond with JSON ret = mco_lews_append_http_header(p_ctx, 200, "application/json"); if (ret != MCO_S_OK) { printf("mco_lews_append_http_header error %d\n", ret); return; } ret = mco_lews_append_header_end(p_ctx); if (ret != MCO_S_OK) { printf("mco_lews_append_header_end error %d\n", ret); return; } ret = mco_lJSON_ctx_open(&json_ctx, p_ctx); if (ret != MCO_S_OK) { printf("mco_lJSON_ctx_open error %d\n", ret); return; } ... // Add JSON data ... mco_lJSON_ctx_close(&json_ctx); ret = mco_lews_flush(p_ctx); if (ret < 0) { printf("mco_lews_flush error %d\n", ret); return; }
MCO_S_OK
MCO_E_NW_SENDERR
MCO_E_LEWS_CLOSING_BRACKET_MISSING