# mcorest_api_json_read_object_begin

Begin reading a JSON object.

### For an overview see page mcorest_api_json_read_*

### Prototype

        MCO_RET mcorest_api_json_read_object_begin( mcorest_api_json_read_ctx_t *ctx );

### Arguments

ctx | Pointer to the JSON read context structure

### Description

This function begins reading a JSON object.

### Return Codes

MCO_S_OK = 0 | Success
MCO_E_REST_* | Any of the Web Services Error Codes

### Example

        static void read_object(void *ctx, mcohs_request_h req);
        {
            MCOREST_API_JSON_TKN_TYPE tkn = MCOREST_API_JSON_TKN_UNKNOWN;
            mcorest_api_json_read_ctx_t jctx;
            mcorest_api_stream_t jstream;
            char key[32];
            int len = sizeof(key);
            long l;

            mcorest_api_stream_with_request(req, &jstream);
            mcorest_api_json_read_start(&jstream, &jctx);

            // Start reading the top-level JSON object
            mcorest_api_json_next_token(&jctx, MCOREST_API_JSON_TKN_OBJECT_BGN, NULL);
            mcorest_api_json_read_object_begin(&jctx);

            // Read first key in the top-level object
            mcorest_api_json_next_token(&jctx, MCOREST_API_JSON_TKN_UNKNOWN, &tkn);
            while (tkn == MCOREST_API_JSON_TKN_STRING)
            {
                // As long as we're getting strings from the object, we interpret them as keys,
                // and then read the values
                mcorest_api_json_read_string(&jctx, 1, 0, key, &len);

                // Read the value type
                mcorest_api_json_next_token(&jctx, MCOREST_API_JSON_TKN_UNKNOWN, &tkn);
                if ((0 == strcmp(key, "max_records") && (tkn == MCOREST_API_JSON_TKN_NUMBER))
                {
                    mcorest_api_json_read_long(&jctx, &l);
                }
                ...
                mcorest_api_json_next_token(&jctx, MCOREST_API_JSON_TKN_UNKNOWN, &tkn);
            }
            mcorest_api_json_read_object_end(jctx);
            ...
        }

### Files

Header file:
mcorestapi.h
Source file:
jsonrd.c
Library:
libmcorest.a