• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SOFTBUS_JSON_UTILS_H
16 #define SOFTBUS_JSON_UTILS_H
17 
18 #include <stdint.h>
19 
20 #include "cJSON.h"
21 #include "string.h"
22 #include "stdbool.h"
23 #include "softbus_log.h"
24 
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif
29 #endif
30 
31 int32_t GetStringItemByJsonObject(const cJSON *json, const char * const string, char *target, uint32_t targetLen);
32 
33 bool GetJsonObjectStringItem(const cJSON *json, const char * const string, char *target, uint32_t targetLen);
34 
35 bool GetJsonObjectNumber16Item(const cJSON *json, const char * const string, uint16_t *target);
36 
37 bool GetJsonObjectNumberItem(const cJSON *json, const char * const string, int *target);
38 
39 bool GetJsonObjectSignedNumberItem(const cJSON *json, const char * const string, int *target);
40 
41 bool GetJsonObjectNumber64Item(const cJSON *json, const char * const string, int64_t *target);
42 
43 bool GetJsonObjectSignedNumber64Item(const cJSON *json, const char * const string, int64_t *target);
44 
45 bool GetJsonObjectDoubleItem(const cJSON *json, const char * const string, double *target);
46 
47 bool GetJsonObjectBoolItem(const cJSON *json, const char * const string, bool *target);
48 
49 bool AddStringToJsonObject(cJSON *json, const char * const string, const char *value);
50 
51 bool AddNumberToJsonObject(cJSON *json, const char * const string, int num);
52 
53 bool AddNumber64ToJsonObject(cJSON *json, const char * const string, int64_t num);
54 
55 bool AddBoolToJsonObject(cJSON *json, const char * const string, bool value);
56 
57 bool GetJsonObjectInt32Item(const cJSON *json, const char * const string, int32_t *target);
58 #ifdef __cplusplus
59 #if __cplusplus
60 }
61 #endif /* __cplusplus */
62 #endif /* __cplusplus */
63 #endif /* SOFTBUS_JSON_UTILS_H */