@@ -128,10 +128,6 @@ cJSON* JSON::release()
128128JSONItem::JSONItem (cJSON* json)
129129 : m_json(json)
130130{
131- if (m_json) {
132- m_propertyName = m_json->string ? m_json->string : " " ;
133- m_type = m_json->type ;
134- }
135131}
136132
137133JSONItem JSONItem::operator [](int index) const
@@ -244,42 +240,6 @@ bool JSONItem::isString() const
244240 return m_json->type == cJSON_String;
245241}
246242
247- void JSONItem::append (const JSONItem& element)
248- {
249- if (!m_json) {
250- return ;
251- }
252-
253- switch (element.getType ()) {
254- case cJSON_False:
255- cJSON_AddFalseToObject (m_json, element.GetPropertyName ().mb_str (wxConvUTF8).data ());
256- break ;
257-
258- case cJSON_True:
259- cJSON_AddTrueToObject (m_json, element.GetPropertyName ().mb_str (wxConvUTF8).data ());
260- break ;
261-
262- case cJSON_NULL:
263- cJSON_AddNullToObject (m_json, element.GetPropertyName ().mb_str (wxConvUTF8).data ());
264- break ;
265-
266- case cJSON_Number:
267- cJSON_AddNumberToObject (m_json, element.GetPropertyName ().mb_str (wxConvUTF8).data (), element.m_valueNumer );
268- break ;
269-
270- case cJSON_String:
271- cJSON_AddStringToObject (m_json,
272- element.GetPropertyName ().mb_str (wxConvUTF8).data (),
273- element.m_valueString .mb_str (wxConvUTF8).data ());
274- break ;
275-
276- case cJSON_Array:
277- case cJSON_Object:
278- cJSON_AddItemToObject (m_json, element.GetPropertyName ().mb_str (wxConvUTF8).data (), element.m_json );
279- break ;
280- }
281- }
282-
283243void JSONItem::arrayAppend (const char * value)
284244{
285245 if (!m_json) {
@@ -304,55 +264,25 @@ void JSONItem::arrayAppend(int number) { arrayAppend((double)number); }
304264
305265void JSONItem::arrayAppend (const wxString& value) { arrayAppend ((const char *)value.mb_str (wxConvUTF8).data ()); }
306266
307- void JSONItem::arrayAppend (const JSONItem& element)
267+ void JSONItem::arrayAppend (JSONItem& & element)
308268{
309269 if (!m_json) {
310270 return ;
311271 }
312-
313- cJSON* p = NULL ;
314- switch (element.getType ()) {
315- case cJSON_False:
316- p = cJSON_CreateFalse ();
317- break ;
318-
319- case cJSON_True:
320- p = cJSON_CreateTrue ();
321- break ;
322-
323- case cJSON_NULL:
324- p = cJSON_CreateNull ();
325- break ;
326-
327- case cJSON_Number:
328- p = cJSON_CreateNumber (element.m_valueNumer );
329- break ;
330-
331- case cJSON_String:
332- p = cJSON_CreateString (element.m_valueString .mb_str (wxConvUTF8).data ());
333- break ;
334- case cJSON_Array:
335- case cJSON_Object:
336- p = element.m_json ;
337- break ;
338- }
339- if (p) {
340- cJSON_AddItemToArray (m_json, p);
272+ if (element.m_json ) {
273+ cJSON_AddItemToArray (m_json, element.m_json );
341274 }
342275}
343276
344277JSONItem JSONItem::createArray ()
345278{
346279 JSONItem arr (cJSON_CreateArray ());
347- arr.setType (cJSON_Array);
348280 return arr;
349281}
350282
351- JSONItem JSONItem::createObject (const wxString& name )
283+ JSONItem JSONItem::createObject ()
352284{
353285 JSONItem obj (cJSON_CreateObject ());
354- obj.SetPropertyName (name);
355- obj.setType (cJSON_Object);
356286 return obj;
357287}
358288
@@ -598,7 +528,7 @@ JSONItem& JSONItem::addProperty(const wxString& name, const wxStringMap_t& strin
598528 JSONItem obj = JSONItem::createObject ();
599529 obj.addProperty (" key" , key);
600530 obj.addProperty (" value" , value);
601- arr.arrayAppend (obj);
531+ arr.arrayAppend (std::move ( obj) );
602532 }
603533 addProperty (name, arr);
604534 return *this ;
@@ -691,8 +621,8 @@ JSONItem JSONItem::AddArray(const wxString& name)
691621
692622JSONItem JSONItem::AddObject (const wxString& name)
693623{
694- JSONItem json = createObject (name );
695- append ( json);
624+ JSONItem json = createObject ();
625+ addProperty (name, json);
696626 return json;
697627}
698628
@@ -757,11 +687,7 @@ std::vector<int> JSONItem::toIntArray(const std::vector<int>& defaultValue) cons
757687
758688JSONItem& JSONItem::addProperty (const wxString& name, const std::vector<int >& arr_int)
759689{
760- if (!m_json) {
761- return *this ;
762- }
763-
764- if (m_type != cJSON_Object) {
690+ if (!m_json || !isObject ()) {
765691 return *this ;
766692 }
767693
0 commit comments