Description

Tells whether the variant contains a value.

Signature

bool success() const;

Return value

  • true if the variant contains a value,
  • false if the variant is empty or invalid.

Remark about null

null is a value in JSON, so this function returns true if the variant contains null.

However, JsonVariant::operator| considers null as an illegal value. So, you can use it to protect against null values.

Example

JsonVariant variant;
bool beforeAssign = variant.success(); // false
variant = 42;
bool afterAssign = variant.success(); // true

See also