class::var::JsonValue

class var::JsonValue
  : public api::WorkObject

Summary

JsonValue()

JsonValue(

json_t * value
)

JsonValue(

const JsonValue & value
)

JsonValue(

JsonValue && a
)

~JsonValue()

int assign(

const var::ConstString & value
)

int assign(

float value
)

int assign(

int value
)

int assign(

bool value
)

int copy(

const JsonValue & value,
bool is_deep
)

bool is_array() const

bool is_false() const

bool is_integer() const

bool is_null() const

bool is_object() const

bool is_real() const

bool is_string() const

bool is_true() const

bool is_valid() const

bool is_zero() const

JsonValue & operator=(

const JsonValue & value
)

JsonValue & operator=(

JsonValue && a
)

const JsonArray & to_array() const

JsonArray & to_array()

bool to_bool() const

float to_float() const

int to_integer() const

const JsonObject & to_object() const

JsonObject & to_object()

var::String to_string() const

JsonValue & to_value()

const JsonValue & to_value() const

enum type type() const

static JsonApi & api()

protected virtual json_t * create()

protected int create_if_not_valid()

enum type

Members

JsonValue()

JsonValue(

json_t * value
)


JsonValue(

const JsonValue & value
)


JsonValue(

JsonValue && a
)


~JsonValue()

int assign(

const var::ConstString & value
)

Assigns a string to the current JSON value.

Parameters

  • value The string to assign

This method will not change the underlying JSON type. If a string value is assigned to a real type, the string will be converted to a real. Consider the following code snippet.

JsonReal real_value(100.0f);
real_value.assign("200.0"); //"200.0" is converted to 200.0f
real_value.assign("Hello World"); //"Hello World" is converted to 0.0f

JsonInteger integer_value(1);

bool_value.assign("2"); //assigns 2
bool_value.assign("3"); /assign 3
bool_value.assign("Hello World"); //assigns 0

int assign(

float value
)


int assign(

int value
)


int assign(

bool value
)


int copy(

const JsonValue & value,
bool is_deep
)


bool is_array() const

bool is_false() const

bool is_integer() const

bool is_null() const

bool is_object() const

bool is_real() const

bool is_string() const

bool is_true() const

bool is_valid() const

Returns true if the value is valid.

JsonObject object;
object.is_valid(); //true - a valid (though empty) object
object.insert("foo", "bar");
object.at("foo").is_valid(); //true
object.at("bar").is_valid(); //false

JsonValue value;
value.is_valid(); //false

JsonValue object_observer(object);

object_observer.is_valid(); //true

bool is_zero() const

JsonValue & operator=(

const JsonValue & value
)


JsonValue & operator=(

JsonValue && a
)


const JsonArray & to_array() const

JsonArray & to_array()

bool to_bool() const

Returns a bool value of the JSON value.

If the value is a string, it will return true if the string is “true” (not case sensitive).

  • INTEGER: true if non-zero
  • FLOAT: true if non-zero
  • TRUE: true
  • FALSE: false
  • NULL: false
  • OBJECT: true
  • ARRAY: true
  • INVALID: false

float to_float() const

Returns a float value of the JSON value.

If the JSON value is of type float, integer, or string, it will be converted to a real number.

Otherwise, 0.0f is returned.


int to_integer() const

Returns an integer value of the JSON value.

If the JSON value is of type float, integer, or string, it will be converted to an integer.

Otherwise, 0 is returned.


const JsonObject & to_object() const

JsonObject & to_object()

var::String to_string() const

Converts the JSON value to string.

Returns

A string representing the value

The following types are converting to a string

  • STRING: as a string
  • INTEGER: as a formatted string
  • FLOAT: as a formatted string
  • TRUE: “true”
  • FALSE: “false”
  • NULL: “null”
  • OBJECT: “{object}”
  • ARRAY: “[array]”
  • INVALID: “

To convert a json object or array to a proper string using Json::stringify().

JsonValue json_value; //can be any JSON type
Json json = json_value;
var::String as_string = json.stringify();

JsonValue & to_value()

const JsonValue & to_value() const

enum type type() const

static JsonApi & api()

protected virtual json_t * create()

protected int create_if_not_valid()

enum type
  • INVALID
  • OBJECT
  • ARRAY
  • STRING
  • REAL
  • INTEGER
  • TRUE
  • FALSE
  • ZERO

X

Thanks for Coming!

Subscribe to news and updates