#ifndef _JSON_ARRAY_H_ #define _JSON_ARRAY_H_ #include "rapidjson/document.h" #include "json_object.h" namespace base { class JSONObject; class JSONArray { public: JSONArray(); virtual ~JSONArray(); JSONArray(const rapidjson::Value::Array& array); JSONArray(const rapidjson::Value::ConstArray& array); JSONArray(JSONArray&& array); int GetInt(int index); uint32_t GetUint(int index); std::string GetString(int index); int64_t GetInt64(int index); uint64_t GetUint64(int index); JSONArray GetArray(int index); JSONObject GetObject(int index) const ; JSONArray& Add(int32_t value); JSONArray& Add(uint32_t value); JSONArray& Add(int64_t value); JSONArray& Add(uint64_t value); JSONArray& Add(bool value); JSONArray& Add(const JSONArray& array); JSONArray& Add(const JSONObject& object); template JSONArray& Add(const T value) { rapidjson::Value tmp(value, doc_.GetAllocator()); doc_.PushBack(tmp, doc_.GetAllocator()); return *this; } int Size() const; bool ParseArray(const std::string& json_str); bool ParseArrayFromFile(const std::string& file_path); std::string ToString() const; std::string ToPrettyString() const; private: friend class JSONObject; rapidjson::Document doc_; }; } /* namespace rapidjson */ #endif