158ec469eSopenharmony_ci/*
258ec469eSopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
358ec469eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
458ec469eSopenharmony_ci * you may not use this file except in compliance with the License.
558ec469eSopenharmony_ci * You may obtain a copy of the License at
658ec469eSopenharmony_ci *
758ec469eSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
858ec469eSopenharmony_ci *
958ec469eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1058ec469eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1158ec469eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1258ec469eSopenharmony_ci * See the License for the specific language governing permissions and
1358ec469eSopenharmony_ci * limitations under the License.
1458ec469eSopenharmony_ci */
1558ec469eSopenharmony_ci
1658ec469eSopenharmony_ci#ifndef MISCDEVICE_JSON_PARSER_H
1758ec469eSopenharmony_ci#define MISCDEVICE_JSON_PARSER_H
1858ec469eSopenharmony_ci
1958ec469eSopenharmony_ci#include <cstdint>
2058ec469eSopenharmony_ci#include <string>
2158ec469eSopenharmony_ci#include <vector>
2258ec469eSopenharmony_ci
2358ec469eSopenharmony_ci#include "cJSON.h"
2458ec469eSopenharmony_ci
2558ec469eSopenharmony_ci#include "raw_file_descriptor.h"
2658ec469eSopenharmony_ci
2758ec469eSopenharmony_cinamespace OHOS {
2858ec469eSopenharmony_cinamespace Sensors {
2958ec469eSopenharmony_ciclass JsonParser {
3058ec469eSopenharmony_cipublic:
3158ec469eSopenharmony_ci    explicit JsonParser(const std::string &filePath);
3258ec469eSopenharmony_ci    explicit JsonParser(const RawFileDescriptor &rawFd);
3358ec469eSopenharmony_ci    ~JsonParser();
3458ec469eSopenharmony_ci    int32_t ParseJsonArray(cJSON *json, const std::string &key, std::vector<std::string> &vals) const;
3558ec469eSopenharmony_ci    int32_t ParseJsonArray(const std::string &key, std::vector<std::string> &vals) const;
3658ec469eSopenharmony_ci    bool HasObjectItem(cJSON *json, const std::string &key) const;
3758ec469eSopenharmony_ci    bool HasObjectItem(const std::string &key) const;
3858ec469eSopenharmony_ci    cJSON *GetObjectItem(cJSON *json, const std::string &key) const;
3958ec469eSopenharmony_ci    cJSON *GetObjectItem(const std::string &key) const;
4058ec469eSopenharmony_ci    bool IsArray(cJSON *json) const;
4158ec469eSopenharmony_ci    int32_t GetArraySize(cJSON *json) const;
4258ec469eSopenharmony_ci    cJSON *GetArrayItem(cJSON *json, int32_t index) const;
4358ec469eSopenharmony_ci    int32_t GetIntValue(cJSON *json) const;
4458ec469eSopenharmony_ci    double GetDoubleValue(cJSON *json) const;
4558ec469eSopenharmony_ci    std::string GetStringValue(cJSON *json) const;
4658ec469eSopenharmony_ci
4758ec469eSopenharmony_ciprivate:
4858ec469eSopenharmony_ci    cJSON *cJson_ = nullptr;
4958ec469eSopenharmony_ci};
5058ec469eSopenharmony_ci} // namespace Sensors
5158ec469eSopenharmony_ci} // namespace OHOS
5258ec469eSopenharmony_ci#endif // MISCDEVICE_JSON_PARSER_H