1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef JSON_HELPER_H 17 #define JSON_HELPER_H 18 19 #include <string> 20 #include "json.hpp" 21 22 namespace OHOS { 23 namespace MultimediaPlugin { 24 class JsonHelper final { 25 public: 26 static uint32_t CheckElementExistence(const nlohmann::json &jsonObject, const std::string &key); 27 static uint32_t GetStringValue(const nlohmann::json &jsonString, std::string &value); 28 static uint32_t GetStringValue(const nlohmann::json &jsonObject, const std::string &key, std::string &value); 29 static uint32_t GetUint32Value(const nlohmann::json &jsonNum, uint32_t &value); 30 static uint32_t GetUint32Value(const nlohmann::json &jsonObject, const std::string &key, uint32_t &value); 31 static uint32_t GetUint16Value(const nlohmann::json &jsonObject, const std::string &key, uint16_t &value); 32 static uint32_t GetArraySize(const nlohmann::json &jsonObject, const std::string &key, size_t &size); 33 34 private: 35 static const nlohmann::json &GetJsonElement(const nlohmann::json &jsonObject, 36 const std::string &key, 37 uint32_t &errorCode); 38 static void PrintElementMissingLog(const std::string &identifier, const std::string &key, uint32_t errorCode); 39 static nlohmann::json nullJson_; 40 }; 41 } // namespace MultimediaPlugin 42 } // namespace OHOS 43 44 #endif // JSON_HELPER_H 45