1 /*
2 * Copyright (c) 2025 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 #include "json_object.h"
17
18 #include "cJSON.h"
19 #include "dm_log.h"
20
21 namespace OHOS {
22 namespace DistributedHardware {
23
GetCJsonPointer(void * pointer)24 static cJSON *GetCJsonPointer(void *pointer)
25 {
26 return static_cast<cJSON*>(pointer);
27 }
28
AddToArray(cJSON * item,cJSON * newItem)29 static bool AddToArray(cJSON *item, cJSON *newItem)
30 {
31 if (item == nullptr) {
32 LOGE("item is nullptr");
33 return false;
34 }
35 if (!cJSON_AddItemToArray(item, newItem)) {
36 LOGE("add item to array fail");
37 cJSON_Delete(newItem);
38 return false;
39 }
40 return true;
41 }
42
ToJson(JsonItemObject & itemObject,const std::string & value)43 void ToJson(JsonItemObject &itemObject, const std::string &value)
44 {
45 if (itemObject.item_ != nullptr) {
46 cJSON_Delete(GetCJsonPointer(itemObject.item_));
47 }
48 itemObject.item_ = cJSON_CreateString(value.c_str());
49 }
50
ToJson(JsonItemObject & itemObject,const char * value)51 void ToJson(JsonItemObject &itemObject, const char *value)
52 {
53 if (itemObject.item_ != nullptr) {
54 cJSON_Delete(GetCJsonPointer(itemObject.item_));
55 }
56 itemObject.item_ = cJSON_CreateString(value);
57 }
58
ToJson(JsonItemObject & itemObject,const double & value)59 void ToJson(JsonItemObject &itemObject, const double &value)
60 {
61 if (itemObject.item_ != nullptr) {
62 cJSON_Delete(GetCJsonPointer(itemObject.item_));
63 }
64 itemObject.item_ = cJSON_CreateNumber(value);
65 }
66
ToJson(JsonItemObject & itemObject,const bool & value)67 void ToJson(JsonItemObject &itemObject, const bool &value)
68 {
69 if (itemObject.item_ != nullptr) {
70 cJSON_Delete(GetCJsonPointer(itemObject.item_));
71 }
72 itemObject.item_ = value ? cJSON_CreateTrue() : cJSON_CreateFalse();
73 }
74
ToJson(JsonItemObject & itemObject,const uint8_t & value)75 void ToJson(JsonItemObject &itemObject, const uint8_t &value)
76 {
77 if (itemObject.item_ != nullptr) {
78 cJSON_Delete(GetCJsonPointer(itemObject.item_));
79 }
80 #ifdef __CJSON_USE_INT64
81 itemObject.item_ = cJSON_CreateInt64Number(value);
82 #else
83 itemObject.item_ = cJSON_CreateNumber(value);
84 #endif
85 }
86
ToJson(JsonItemObject & itemObject,const int16_t & value)87 void ToJson(JsonItemObject &itemObject, const int16_t &value)
88 {
89 if (itemObject.item_ != nullptr) {
90 cJSON_Delete(GetCJsonPointer(itemObject.item_));
91 }
92 #ifdef __CJSON_USE_INT64
93 itemObject.item_ = cJSON_CreateInt64Number(value);
94 #else
95 itemObject.item_ = cJSON_CreateNumber(value);
96 #endif
97 }
98
ToJson(JsonItemObject & itemObject,const uint16_t & value)99 void ToJson(JsonItemObject &itemObject, const uint16_t &value)
100 {
101 if (itemObject.item_ != nullptr) {
102 cJSON_Delete(GetCJsonPointer(itemObject.item_));
103 }
104 #ifdef __CJSON_USE_INT64
105 itemObject.item_ = cJSON_CreateInt64Number(value);
106 #else
107 itemObject.item_ = cJSON_CreateNumber(value);
108 #endif
109 }
110
ToJson(JsonItemObject & itemObject,const int32_t & value)111 void ToJson(JsonItemObject &itemObject, const int32_t &value)
112 {
113 if (itemObject.item_ != nullptr) {
114 cJSON_Delete(GetCJsonPointer(itemObject.item_));
115 }
116 #ifdef __CJSON_USE_INT64
117 itemObject.item_ = cJSON_CreateInt64Number(value);
118 #else
119 itemObject.item_ = cJSON_CreateNumber(value);
120 #endif
121 }
122
ToJson(JsonItemObject & itemObject,const uint32_t & value)123 void ToJson(JsonItemObject &itemObject, const uint32_t &value)
124 {
125 if (itemObject.item_ != nullptr) {
126 cJSON_Delete(GetCJsonPointer(itemObject.item_));
127 }
128 #ifdef __CJSON_USE_INT64
129 itemObject.item_ = cJSON_CreateInt64Number(value);
130 #else
131 itemObject.item_ = cJSON_CreateNumber(value);
132 #endif
133 }
134
ToJson(JsonItemObject & itemObject,const int64_t & value)135 void ToJson(JsonItemObject &itemObject, const int64_t &value)
136 {
137 if (itemObject.item_ != nullptr) {
138 cJSON_Delete(GetCJsonPointer(itemObject.item_));
139 }
140 #ifdef __CJSON_USE_INT64
141 itemObject.item_ = cJSON_CreateInt64Number(value);
142 #else
143 itemObject.item_ = cJSON_CreateNumber(value);
144 #endif
145 }
146
ToJson(JsonItemObject & itemObject,const uint64_t & value)147 void ToJson(JsonItemObject &itemObject, const uint64_t &value)
148 {
149 if (itemObject.item_ != nullptr) {
150 cJSON_Delete(GetCJsonPointer(itemObject.item_));
151 }
152 #ifdef __CJSON_USE_INT64
153 itemObject.item_ = cJSON_CreateInt64Number(value);
154 #else
155 itemObject.item_ = cJSON_CreateNumber(value);
156 #endif
157 }
158
FromJson(const JsonItemObject & itemObject,std::string & value)159 void FromJson(const JsonItemObject &itemObject, std::string &value)
160 {
161 itemObject.GetTo(value);
162 }
163
FromJson(const JsonItemObject & itemObject,double & value)164 void FromJson(const JsonItemObject &itemObject, double &value)
165 {
166 itemObject.GetTo(value);
167 }
168
FromJson(const JsonItemObject & itemObject,bool & value)169 void FromJson(const JsonItemObject &itemObject, bool &value)
170 {
171 itemObject.GetTo(value);
172 }
173
FromJson(const JsonItemObject & itemObject,uint8_t & value)174 void FromJson(const JsonItemObject &itemObject, uint8_t &value)
175 {
176 int32_t tmpValue = 0;
177 itemObject.GetTo(tmpValue);
178 value = static_cast<uint8_t>(tmpValue);
179 }
180
FromJson(const JsonItemObject & itemObject,int16_t & value)181 void FromJson(const JsonItemObject &itemObject, int16_t &value)
182 {
183 int32_t tmpValue = 0;
184 itemObject.GetTo(tmpValue);
185 value = static_cast<int16_t>(tmpValue);
186 }
187
FromJson(const JsonItemObject & itemObject,uint16_t & value)188 void FromJson(const JsonItemObject &itemObject, uint16_t &value)
189 {
190 int32_t tmpValue = 0;
191 itemObject.GetTo(tmpValue);
192 value = static_cast<uint16_t>(tmpValue);
193 }
194
FromJson(const JsonItemObject & itemObject,int32_t & value)195 void FromJson(const JsonItemObject &itemObject, int32_t &value)
196 {
197 itemObject.GetTo(value);
198 }
199
FromJson(const JsonItemObject & itemObject,uint32_t & value)200 void FromJson(const JsonItemObject &itemObject, uint32_t &value)
201 {
202 int32_t tmpValue = 0;
203 itemObject.GetTo(tmpValue);
204 value = static_cast<uint32_t>(tmpValue);
205 }
206
FromJson(const JsonItemObject & itemObject,int64_t & value)207 void FromJson(const JsonItemObject &itemObject, int64_t &value)
208 {
209 itemObject.GetTo(value);
210 }
211
FromJson(const JsonItemObject & itemObject,uint64_t & value)212 void FromJson(const JsonItemObject &itemObject, uint64_t &value)
213 {
214 int64_t tmpValue = 0;
215 itemObject.GetTo(tmpValue);
216 value = static_cast<uint64_t>(tmpValue);
217 }
218
ToString(const JsonItemObject & jsonItem)219 std::string ToString(const JsonItemObject &jsonItem)
220 {
221 return jsonItem.Dump();
222 }
223
JsonItemObject()224 JsonItemObject::JsonItemObject()
225 {}
226
JsonItemObject(const JsonItemObject & object)227 JsonItemObject::JsonItemObject(const JsonItemObject &object)
228 {
229 item_ = object.item_;
230 parent_ = object.parent_;
231 itemName_ = object.itemName_;
232 needDeleteItem_ = object.needDeleteItem_;
233 if (object.needDeleteItem_) {
234 item_ = cJSON_Duplicate(GetCJsonPointer(object.item_), cJSON_True);
235 }
236 }
237
~JsonItemObject()238 JsonItemObject::~JsonItemObject()
239 {
240 Delete();
241 }
242
Delete()243 void JsonItemObject::Delete()
244 {
245 if (needDeleteItem_ && item_ != nullptr) {
246 cJSON_Delete(GetCJsonPointer(item_));
247 }
248 item_ = nullptr;
249 }
250
IsString() const251 bool JsonItemObject::IsString() const
252 {
253 if (item_ == nullptr) {
254 return false;
255 }
256 return cJSON_IsString(GetCJsonPointer(item_));
257 }
258
IsNumber() const259 bool JsonItemObject::IsNumber() const
260 {
261 if (item_ == nullptr) {
262 return false;
263 }
264 return cJSON_IsNumber(GetCJsonPointer(item_));
265 }
266
267 #ifdef __CJSON_USE_INT64
IsNumberInteger() const268 bool JsonItemObject::IsNumberInteger() const
269 {
270 if (item_ == nullptr) {
271 return false;
272 }
273 return cJSON_IsInt64Number(GetCJsonPointer(item_));
274 }
275 #else
IsNumberInteger() const276 bool JsonItemObject::IsNumberInteger() const
277 {
278 if (!IsNumber()) {
279 return false;
280 }
281 double value = 0.0;
282 GetTo(value);
283 return ((value - static_cast<int64_t>(value)) == 0);
284 }
285 #endif
286
IsArray() const287 bool JsonItemObject::IsArray() const
288 {
289 if (item_ == nullptr) {
290 return false;
291 }
292 return cJSON_IsArray(GetCJsonPointer(item_));
293 }
294
IsBoolean() const295 bool JsonItemObject::IsBoolean() const
296 {
297 if (item_ == nullptr) {
298 return false;
299 }
300 return cJSON_IsBool(GetCJsonPointer(item_));
301 }
302
IsObject() const303 bool JsonItemObject::IsObject() const
304 {
305 if (item_ == nullptr) {
306 return false;
307 }
308 return cJSON_IsObject(GetCJsonPointer(item_));
309 }
310
Insert(const std::string & key,const JsonItemObject & object)311 void JsonItemObject::Insert(const std::string &key, const JsonItemObject &object)
312 {
313 if (item_ == nullptr || object.item_ == nullptr) {
314 LOGE("invalid item or object item");
315 return;
316 }
317 cJSON *newItem = cJSON_Duplicate(GetCJsonPointer(object.item_), cJSON_True);
318 if (newItem == nullptr) {
319 LOGE("copy item fail");
320 return;
321 }
322 if (cJSON_GetObjectItemCaseSensitive(GetCJsonPointer(item_), key.c_str()) != nullptr) {
323 cJSON_DeleteItemFromObjectCaseSensitive(GetCJsonPointer(item_), key.c_str());
324 }
325 if (!cJSON_AddItemToObject(GetCJsonPointer(item_), key.c_str(), newItem)) {
326 LOGE("add new item to object fail");
327 cJSON_Delete(newItem);
328 }
329 }
330
operator =(const JsonItemObject & object)331 JsonItemObject& JsonItemObject::operator=(const JsonItemObject &object)
332 {
333 item_ = object.item_;
334 parent_ = object.parent_;
335 itemName_ = object.itemName_;
336 itemIndex_ = object.itemIndex_;
337 needDeleteItem_ = object.needDeleteItem_;
338 if (object.needDeleteItem_) {
339 item_ = cJSON_Duplicate(GetCJsonPointer(object.item_), cJSON_True);
340 }
341 return *this;
342 }
343
DumpFormated() const344 std::string JsonItemObject::DumpFormated() const
345 {
346 return Dump(true, true);
347 }
348
Dump() const349 std::string JsonItemObject::Dump() const
350 {
351 return Dump(false, true);
352 }
353
Dump(bool formatFlag,bool isIgnoreError) const354 std::string JsonItemObject::Dump(bool formatFlag, bool isIgnoreError) const
355 {
356 (void) isIgnoreError;
357 if (item_ == nullptr) {
358 LOGE("item_ is nullptr");
359 return "";
360 }
361 cJSON *jsonItem = GetCJsonPointer(item_);
362 char* jsonString = formatFlag ? cJSON_Print(jsonItem) : cJSON_PrintUnformatted(jsonItem);
363 if (jsonString == nullptr) {
364 return "";
365 }
366 std::string out(jsonString);
367 cJSON_free(jsonString);
368 return out;
369 }
370
operator [](const std::string & key)371 JsonItemObject JsonItemObject::operator[](const std::string &key)
372 {
373 JsonItemObject itemObject = At(key);
374 if (itemObject.item_ == nullptr) {
375 itemObject.item_ = cJSON_CreateNull();
376 if (itemObject.item_ == nullptr) {
377 return itemObject;
378 }
379 if (!cJSON_AddItemToObject(GetCJsonPointer(item_), key.c_str(), GetCJsonPointer(itemObject.item_))) {
380 LOGE("add item to object fail");
381 cJSON_Delete(GetCJsonPointer(itemObject.item_));
382 itemObject.item_ = nullptr;
383 } else {
384 itemObject.beValid_ = true;
385 }
386 }
387 return itemObject;
388 }
389
operator [](const std::string & key) const390 const JsonItemObject JsonItemObject::operator[](const std::string &key) const
391 {
392 return At(key);
393 }
394
Contains(const std::string & key) const395 bool JsonItemObject::Contains(const std::string &key) const
396 {
397 if (item_ == nullptr) {
398 LOGE("item_ is nullptr");
399 return false;
400 }
401 cJSON* item = cJSON_GetObjectItemCaseSensitive(GetCJsonPointer(item_), key.c_str());
402 return (item != nullptr);
403 }
404
IsDiscarded() const405 bool JsonItemObject::IsDiscarded() const
406 {
407 return (item_ == nullptr);
408 }
409
PushBack(const std::string & strValue)410 bool JsonItemObject::PushBack(const std::string &strValue)
411 {
412 if (item_ == nullptr) {
413 LOGE("item_ is nullptr");
414 return false;
415 }
416 if (GetCJsonPointer(item_)->type != cJSON_Array) {
417 LOGE("item_ type is not array");
418 return false;
419 }
420 cJSON *newItem = cJSON_CreateString(strValue.c_str());
421 return AddToArray(GetCJsonPointer(item_), newItem);
422 }
423
PushBack(const double & value)424 bool JsonItemObject::PushBack(const double &value)
425 {
426 if (item_ == nullptr) {
427 LOGE("item_ is nullptr");
428 return false;
429 }
430 if (GetCJsonPointer(item_)->type != cJSON_Array) {
431 LOGE("item_ type is not array");
432 return false;
433 }
434 cJSON *newItem = cJSON_CreateNumber(value);
435 return AddToArray(GetCJsonPointer(item_), newItem);
436 }
437
PushBack(const int64_t & value)438 bool JsonItemObject::PushBack(const int64_t &value)
439 {
440 if (item_ == nullptr) {
441 LOGE("item_ is nullptr");
442 return false;
443 }
444 if (GetCJsonPointer(item_)->type != cJSON_Array) {
445 LOGE("item_ type is not array");
446 return false;
447 }
448 #ifdef __CJSON_USE_INT64
449 cJSON *newItem = cJSON_CreateInt64Number(value);
450 #else
451 cJSON *newItem = cJSON_CreateNumber(static_cast<double>(value));
452 #endif
453 return AddToArray(GetCJsonPointer(item_), newItem);
454 }
455
PushBack(const JsonItemObject & item)456 bool JsonItemObject::PushBack(const JsonItemObject &item)
457 {
458 if (item_ == nullptr) {
459 LOGE("item_ is nullptr");
460 return false;
461 }
462 if (!item.beValid_ || !beValid_) {
463 return false;
464 }
465 if (GetCJsonPointer(item_)->type != cJSON_Array) {
466 LOGE("item_ type is not array");
467 return false;
468 }
469 cJSON* newItem = cJSON_Duplicate(GetCJsonPointer(item.item_), cJSON_True);
470 return AddToArray(GetCJsonPointer(item_), newItem);
471 }
472
AddItemToArray(JsonItemObject & item)473 void JsonItemObject::AddItemToArray(JsonItemObject &item)
474 {
475 cJSON* jsonItem = GetCJsonPointer(item_);
476 if (cJSON_AddItemToArray(jsonItem, GetCJsonPointer(item.item_))) {
477 item.itemIndex_ = cJSON_GetArraySize(jsonItem) - 1;
478 } else if (item.item_ != nullptr) {
479 // item add fail, need delete
480 item.needDeleteItem_ = true;
481 }
482 }
483
Key() const484 std::string JsonItemObject::Key() const
485 {
486 if (item_ != nullptr) {
487 return std::string(GetCJsonPointer(item_)->string);
488 }
489 return itemName_;
490 }
491
At(const std::string & key) const492 JsonItemObject JsonItemObject::At(const std::string &key) const
493 {
494 JsonItemObject operationItem;
495 operationItem.item_ = cJSON_GetObjectItemCaseSensitive(GetCJsonPointer(item_), key.c_str());
496 if (operationItem.item_ != nullptr) {
497 operationItem.beValid_ = true;
498 }
499 operationItem.parent_ = item_;
500 operationItem.itemName_ = key;
501 return operationItem;
502 }
503
GetTo(std::string & value) const504 void JsonItemObject::GetTo(std::string &value) const
505 {
506 value = "";
507 if (item_ == nullptr) {
508 LOGE("value item is null");
509 return;
510 }
511 if (!IsString()) {
512 return;
513 }
514 const char* strValue = cJSON_GetStringValue(GetCJsonPointer(item_));
515 if (strValue == nullptr) {
516 return;
517 }
518 value = std::string(strValue);
519 }
520
GetTo(double & value) const521 void JsonItemObject::GetTo(double &value) const
522 {
523 value = 0.0;
524 if (item_ == nullptr) {
525 LOGE("value item is null");
526 return;
527 }
528 if (!IsNumber()) {
529 return;
530 }
531 value = cJSON_GetNumberValue(GetCJsonPointer(item_));
532 }
533
GetTo(int32_t & value) const534 void JsonItemObject::GetTo(int32_t &value) const
535 {
536 int64_t tmpValue = 0;
537 GetTo(tmpValue);
538 value = static_cast<int32_t>(tmpValue);
539 }
540
GetTo(uint32_t & value) const541 void JsonItemObject::GetTo(uint32_t &value) const
542 {
543 int64_t tmpValue = 0;
544 GetTo(tmpValue);
545 value = static_cast<uint32_t>(tmpValue);
546 }
547
GetTo(int64_t & value) const548 void JsonItemObject::GetTo(int64_t &value) const
549 {
550 value = 0;
551 if (item_ == nullptr) {
552 LOGE("value item is null");
553 return;
554 }
555 if (!IsNumberInteger()) {
556 return;
557 }
558 #ifdef __CJSON_USE_INT64
559 long long *pValue = cJSON_GetInt64NumberValue(GetCJsonPointer(item_));
560 if (pValue == nullptr) {
561 LOGE("value is null");
562 return;
563 }
564 value = *pValue;
565 #else
566 double tmpValue = cJSON_GetNumberValue(GetCJsonPointer(item_));
567 value = static_cast<int64_t>(tmpValue);
568 #endif
569 }
570
GetTo(bool & value) const571 void JsonItemObject::GetTo(bool &value) const
572 {
573 value = false;
574 if (item_ == nullptr) {
575 LOGE("value item is null");
576 return;
577 }
578 if (!IsBoolean()) {
579 return;
580 }
581 value = cJSON_IsTrue(GetCJsonPointer(item_)) ? true : false;
582 }
583
Items() const584 std::vector<JsonItemObject> JsonItemObject::Items() const
585 {
586 std::vector<JsonItemObject> items;
587 if (item_ == nullptr) {
588 return items;
589 }
590 cJSON *current = nullptr;
591 cJSON *jsonItem = GetCJsonPointer(item_);
592 if (jsonItem->type == cJSON_Object || jsonItem->type == cJSON_Array) {
593 cJSON_ArrayForEach(current, jsonItem) {
594 JsonItemObject child;
595 child.item_ = current;
596 child.parent_ = item_;
597 items.push_back(child);
598 }
599 }
600 return items;
601 }
602
InitItem(JsonItemObject & item)603 bool JsonItemObject::InitItem(JsonItemObject &item)
604 {
605 if (!beValid_) {
606 LOGE("invalid item");
607 return false;
608 }
609 item.item_ = cJSON_CreateObject();
610 if (item.item_ == nullptr) {
611 LOGE("create new object item fail");
612 return false;
613 }
614 item.parent_ = parent_;
615 item.beValid_ = true;
616 item.itemName_ = itemName_;
617 item.itemIndex_ = itemIndex_;
618 return true;
619 }
620
InitArray()621 bool JsonItemObject::InitArray()
622 {
623 if (!beValid_) {
624 return false;
625 }
626 cJSON *newItem = cJSON_CreateArray();
627 if (newItem == nullptr) {
628 return false;
629 }
630 if (!ReplaceItem(newItem)) {
631 cJSON_Delete(newItem);
632 return false;
633 }
634 return true;
635 }
636
ReplaceItem(void * newItem)637 bool JsonItemObject::ReplaceItem(void *newItem)
638 {
639 if (parent_ != nullptr) {
640 cJSON *jsonParent = GetCJsonPointer(parent_);
641 if (cJSON_IsObject(jsonParent)) {
642 if (!cJSON_ReplaceItemInObjectCaseSensitive(jsonParent, itemName_.c_str(), GetCJsonPointer(newItem))) {
643 LOGE("replace item in object fail, itemName:%{public}s", itemName_.c_str());
644 return false;
645 }
646 } else if (cJSON_IsArray(jsonParent) && itemIndex_ >= 0 && itemIndex_ < cJSON_GetArraySize(jsonParent)) {
647 if (!cJSON_ReplaceItemInArray(jsonParent, itemIndex_, GetCJsonPointer(newItem))) {
648 LOGE("replace item in array fail, itemIndex:%{public}d", itemIndex_);
649 return false;
650 }
651 }
652 } else {
653 cJSON_Delete(GetCJsonPointer(item_));
654 }
655 item_ = newItem;
656 return true;
657 }
658
Erase(const std::string & key)659 void JsonItemObject::Erase(const std::string &key)
660 {
661 if (item_ == nullptr) {
662 return;
663 }
664 if (IsObject()) {
665 cJSON_DeleteItemFromObjectCaseSensitive(GetCJsonPointer(item_), key.c_str());
666 }
667 }
668
669
JsonObject(JsonCreateType type)670 JsonObject::JsonObject(JsonCreateType type)
671 {
672 needDeleteItem_ = true;
673 beValid_ = true;
674 if (type == JsonCreateType::JSON_CREATE_TYPE_OBJECT) {
675 item_ = cJSON_CreateObject();
676 } else {
677 item_ = cJSON_CreateArray();
678 }
679 }
680
JsonObject(const std::string & strJson)681 JsonObject::JsonObject(const std::string &strJson)
682 {
683 needDeleteItem_ = true;
684 beValid_ = true;
685 Parse(strJson);
686 }
687
~JsonObject()688 JsonObject::~JsonObject()
689 {
690 Delete();
691 }
692
Parse(const std::string & strJson)693 bool JsonObject::Parse(const std::string &strJson)
694 {
695 Delete();
696 if (!strJson.empty()) {
697 item_ = cJSON_Parse(strJson.c_str());
698 return true;
699 }
700 LOGE("strJson is empty");
701 return false;
702 }
703
Duplicate(const JsonObject & object)704 void JsonObject::Duplicate(const JsonObject &object)
705 {
706 Delete();
707 item_ = cJSON_Duplicate(GetCJsonPointer(object.item_), cJSON_True);
708 }
709
710 } // namespace DistributedHardware
711 } // namespace OHOS