123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #pragma once
- #include "Text.h"
- #include "Array.h"
- namespace Framework
- {
- namespace JSON
- {
- enum JSONType
- {
- NULL_,
- BOOLEAN,
- NUMBER,
- STRING,
- ARRAY,
- OBJECT
- };
- class JSONArray;
- class JSONObject;
- class JSONValue
- {
- private:
- JSONType type;
- protected:
- JSONValue( JSONType type );
- public:
- JSONValue();
- JSONType getType() const;
- virtual Text toString() const;
- };
- class JSONBool : public JSONValue
- {
- private:
- bool b;
- public:
- JSONBool( bool b );
- bool getBool() const;
- Text toString() const override;
- };
- class JSONNumber : public JSONValue
- {
- private:
- double number;
- public:
- JSONNumber( double num );
- double getNumber() const;
- Text toString() const override;
- };
- class JSONString : public JSONValue
- {
- private:
- Text string;
- public:
- JSONString( Text string );
- Text getString() const;
- Text toString() const override;
- };
- class JSONArray : public JSONValue
- {
- private:
- Array< JSONValue > *array;
- public:
- JSONArray();
- JSONArray( Text string );
- JSONArray( const JSONArray &arr );
- ~JSONArray();
- JSONArray &operator=( const JSONArray &arr );
- void addValue( JSONValue value );
- JSONValue getValue( int i ) const;
- int getLength() const;
- Text toString() const override;
- };
- class JSONObject : public JSONValue
- {
- private:
- Array< Text > *fields;
- Array< JSONValue > *values;
- public:
- JSONObject();
- JSONObject( Text string );
- JSONObject( const JSONObject &obj );
- ~JSONObject();
- JSONObject &operator=( const JSONObject &obj );
- bool addValue( Text field, JSONValue value );
- bool removeValue( Text field );
- bool hasValue( Text field );
- JSONValue getValue( Text field );
- Iterator< Text > getFields();
- Iterator< JSONValue > getValues();
- Text toString() const override;
- };
- namespace Parser
- {
- int findObjectEndInArray( const char *str );
- Text removeWhitespace( const char *str );
- JSONValue getValue( const char *str );
- int findFieldEndInObject( const char *str );
- int findValueEndInObject( const char *str );
- };
- }
- }
|