12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #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 <typename T>
- 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
|