Begin reading a JSON object.
MCO_RET mcorest_api_json_read_object_begin( mcorest_api_json_read_ctx_t *ctx );
| ctx | Pointer to the JSON read context structure |
This function begins reading a JSON object.
| MCO_S_OK = 0 | Success |
| MCO_E_REST_* | Any of the Web Services Error Codes |
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);
...
}