Skip to content

Commit 607acab

Browse files
author
Joe Andolina
committed
Updated the object filter implementation
1 parent 7ab7c5a commit 607acab

File tree

1 file changed

+2
-61
lines changed

1 file changed

+2
-61
lines changed

src/JSONVar.cpp

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,11 @@ void JSONVar::replaceJson(struct cJSON* json)
414414
//---------------------------------------------------------------------
415415

416416
bool JSONVar::hasPropertyEqual(const char* key, const char* value) const {
417-
// Serial.printf("JSONVar::hasPropertyEqual - %s == %s\n", key, value);
418-
419417
if (!cJSON_IsObject(_json)) {
420418
return false;
421419
}
422420

423421
cJSON* json = cJSON_GetObjectItemCaseSensitive(_json, key);
424-
// Serial.printf("JSONVar::hasPropertyEqual - Found %s\n", json->valuestring);
425422
return json != NULL && strcmp(value, json->valuestring) == 0;
426423
}
427424

@@ -445,72 +442,16 @@ bool JSONVar::hasPropertyEqual(const String& key, const JSONVar& value) const
445442

446443
//---------------------------------------------------------------------
447444

448-
// JSONVar JSONVar::filter(const char* key, const char* value) const {
449-
// JSONVar item;
450-
// cJSON* test;
451-
// cJSON* json = cJSON_CreateArray();
452-
453-
// Serial.printf("JSONVar::filter - %s == %s\n", key, value);
454-
455-
// // if(!cJSON_IsArray(_json)){
456-
// // // target = cJSON_CreateArray();
457-
// // // cJSON_AddItemToArray(target, _json);
458-
// // return (*this);
459-
// // }
460-
461-
// // Serial.printf("JSON SIZE %d", cJSON_GetArraySize(_json));
462-
463-
// Serial.printf("This an array %d\n", (*this).length());
464-
465-
// for (int i = 0; i < (*this).length(); i++) {
466-
// Serial.println("GettingItem");
467-
// item = this[(int)i];
468-
// Serial.println(item);
469-
// Serial.println(item[(const char*)key]);
470-
// Serial.println("GotItem");
471-
472-
// // Serial.println("Loop " + String(i));
473-
// // Serial.println(this->operator[](i));//cJSON_GetArrayItem(_json, i);
474-
475-
// // if (item == NULL) {
476-
// // Serial.println("Loop Null");
477-
// // continue;
478-
// // }
479-
480-
// if(item.hasPropertyEqual(key, value)){
481-
// Serial.println("Got Match");
482-
// return item;
483-
// }
484-
// else {
485-
// Serial.println("NO Match");
486-
// }
487-
// }
488-
489-
// if(cJSON_GetArraySize(json) == 0){
490-
// Serial.println("Returning Null");
491-
// return NULL;
492-
// }
493-
// else if(cJSON_GetArraySize(json) == 1){
494-
// Serial.println("Returning Single");
495-
// return JSONVar(cJSON_GetArrayItem(json, 0), (*this)._json);
496-
// }
497-
498-
// // Serial.println("Returning Array");
499-
// return JSONVar();
500-
// }
501-
502445
JSONVar JSONVar::filter(const char* key, const char* value) const {
503446
cJSON* item;
504447
cJSON* test;
505448
cJSON* json = cJSON_CreateArray();
506449

507-
Serial.printf("JSONVar::filter - %s == %s\n", key, value);
508-
509-
if(!cJSON_IsArray(_json)){
450+
if(cJSON_IsObject(_json)){
510451
test = cJSON_GetObjectItem(_json, key);
511452

512453
if(test != NULL && strcmp(value, test->valuestring) == 0){
513-
return JSONVar(cJSON_Duplicate(item,true), _json);
454+
return (*this);
514455
}
515456
}
516457

0 commit comments

Comments
 (0)