diff options
-rw-r--r-- | include/tgbot/TgTypeParser.h | 9 | ||||
-rw-r--r-- | src/Api.cpp | 2 |
2 files changed, 10 insertions, 1 deletions
diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 759dc2f..f7c9791 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -110,6 +110,15 @@ public: } template<typename T> + std::vector<std::shared_ptr<T>> parseJsonAndGetArray(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data) const { + std::vector<std::shared_ptr<T>> result; + for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : data) { + result.push_back((this->*parseFunc)(innerTreeItem.second)); + } + return result; + } + + template<typename T> std::vector<std::shared_ptr<T>> parseJsonAndGetArray(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { std::vector<std::shared_ptr<T>> result; auto treeItem = data.find(keyName); diff --git a/src/Api.cpp b/src/Api.cpp index 7e05621..9c8259f 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -246,7 +246,7 @@ vector<Update::Ptr> Api::getUpdates(int32_t offset, int32_t limit, int32_t timeo if (timeout) { args.push_back(HttpReqArg("timeout", timeout)); } - return TgTypeParser::getInstance().parseJsonAndGetArray<Update>(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args), "result"); + return TgTypeParser::getInstance().parseJsonAndGetArray<Update>(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args)); } void Api::setWebhook(const string& url) const { |