MCO_RET mco_lJSON_obj_add_int(lews_JSON_context_h json_ctx, const char *key, int value);
json_ctx
lews_JSON_context_t structure.key
value
This function adds a numeric key-value pair to the current JSON object (e.g.,
"x": 10).The integer value is converted to its decimal string representation and inserted without quotes, as required by the JSON standard.
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 key-value pair.
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, "position"); if (ret == MCO_S_OK) { ret = mco_lJSON_obj_add_int(&json_ctx, "x", 10); if (ret != MCO_S_OK) { printf("mco_lJSON_obj_add_int error %d\n", ret); } ret = mco_lJSON_obj_add_int(&json_ctx, "y", -17); if (ret != MCO_S_OK) { printf("mco_lJSON_obj_add_int 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_OBJECT