BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdljsn_jsontype

Detailed Description

Outline

Purpose

Enumerate the set of JSON value types.

Classes

See also
bdljsn_json, bdljsn_jsonutil, bdljsn_jsonvalue

Description

This component provides a namespace for the enum type bdljsn::JsonType::Enum, which enumerates the set of fundamental JSON types in the JSON specification (see http://json.org).

Enumerators

Name Description
------------- ---------------------------------------------------
e_OBJECT A JSON object
e_ARRAY A JSON array
e_STRING A JSON string
e_NUMBER A JSON number
e_BOOLEAN true or false
e_NULL null

Usage

This section illustrates intended use of this component.

Example 1: Basic Syntax

The following snippets of code provide a simple illustration of using bdljsn::JsonType.

First, we create a variable value of type bdljsn::JsonType::Enum and initialize it with the enumerator value bdljsn::JsonType::e_STRING:

Enum
Definition bdljsn_jsontype.h:127
@ e_STRING
Definition bdljsn_jsontype.h:130

Now, we store the address of its ASCII representation in a pointer variable, asciiValue, of type const char *:

const char *asciiValue = bdljsn::JsonType::toAscii(value);
assert(0 == bsl::strcmp(asciiValue, "STRING"));
static const char * toAscii(JsonType::Enum value)

Finally, we print value to bsl::cout.

bsl::cout << value << bsl::endl;

This statement produces the following output on stdout:

STRING