CMSC23740 Common Code Library
Support code for CS23740 programming projects
Loading...
Searching...
No Matches
json::Object Class Reference

JSON objects. More...

#include <json.hpp>

Inheritance diagram for json::Object:
Collaboration diagram for json::Object:

Public Member Functions

 Object ()
 ~Object ()
int size () const
 return the number of fields in the object
void insert (std::string key, Value *val)
 insert a key-value pair into the object
Value * operator[] (std::string key) const
const Object * fieldAsObject (std::string key) const
const Array * fieldAsArray (std::string key) const
const Number * fieldAsNumber (std::string key) const
const Integer * fieldAsInteger (std::string key) const
const Real * fieldAsReal (std::string key) const
const String * fieldAsString (std::string key) const
const Bool * fieldAsBool (std::string key) const
std::string toString ()
Public Member Functions inherited from json::Value
Type type () const
 return the type of this JSON value
bool isObject () const
 return true if this value is an object
bool isArray () const
 return true if this value is an array
bool isNumber () const
 return true if this value is a number
bool isInteger () const
 return true if this value is an integer
bool isReal () const
 return true if this value is a real number
bool isString () const
 return true if this value is a string
bool isBool () const
 return true if this value is a boolean
bool isNull () const
 return true if this value is the null value
const Object * asObject () const
 dynamic cast to JSON object
const Array * asArray () const
 dynamic cast to JSON array
const Number * asNumber () const
 dynamic cast to JSON number
const Integer * asInteger () const
 dynamic cast to JSON integer
const Real * asReal () const
 dynamic cast to JSON real number
const String * asString () const
 dynamic cast to JSON string
const Bool * asBool () const
 dynamic cast to JSON boolean
virtual ~Value ()

Additional Inherited Members

Protected Member Functions inherited from json::Value
 Value (Type ty)
Protected Attributes inherited from json::Value
Type _ty

Detailed Description

JSON objects.

Constructor & Destructor Documentation

◆ Object()

json::Object::Object ( )
inline

◆ ~Object()

json::Object::~Object ( )

Member Function Documentation

◆ fieldAsArray()

const Array * json::Object::fieldAsArray ( std::string key) const
inline

return an array-valued field

Returns
nullptr if the field is not present or is not an array

◆ fieldAsBool()

const Bool * json::Object::fieldAsBool ( std::string key) const
inline

return an bool-valued field

Returns
nullptr if the field is not present or is not a bool

◆ fieldAsInteger()

const Integer * json::Object::fieldAsInteger ( std::string key) const
inline

return an integer-valued field

Returns
nullptr if the field is not present or is not an integer

◆ fieldAsNumber()

const Number * json::Object::fieldAsNumber ( std::string key) const
inline

return a number-valued field

Returns
nullptr if the field is not present or is not a number

◆ fieldAsObject()

const Object * json::Object::fieldAsObject ( std::string key) const
inline

return an object-valued field

Returns
nullptr if the field is not present or is not an object

◆ fieldAsReal()

const Real * json::Object::fieldAsReal ( std::string key) const
inline

return an real-valued field

Returns
nullptr if the field is not present or is not a real

◆ fieldAsString()

const String * json::Object::fieldAsString ( std::string key) const
inline

return an string-valued field

Returns
nullptr if the field is not present or is not a string

◆ insert()

void json::Object::insert ( std::string key,
Value * val )

insert a key-value pair into the object

◆ operator[]()

Value * json::Object::operator[] ( std::string key) const

return the value corresponding to the given key.

Returns
nil if the key is not defined in the object

◆ size()

int json::Object::size ( ) const
inline

return the number of fields in the object

◆ toString()

std::string json::Object::toString ( )
virtual

Implements json::Value.


The documentation for this class was generated from the following file:
  • /Users/jhr/Classes/23740/f2026/solutions/cs237-library/include/json.hpp