@@ -412,4 +412,58 @@ void JSONVar::replaceJson(struct cJSON* json)
412
412
}
413
413
}
414
414
415
+ // ---------------------------------------------------------------------
416
+
417
+ bool JSONVar::hasPropertyEqualTo (const String& key, String& value) const {
418
+ return hasPropertyEqualTo (key.c_str (), value.c_str ());
419
+ }
420
+
421
+ // ---------------------------------------------------------------------
422
+
423
+ bool JSONVar::hasPropertyEqualTo (const char * key, const char * value) const {
424
+ if (!hasProperty (sourceProperty)){
425
+ return false ;
426
+ }
427
+
428
+ if (strcmp (targetValue, source[sourceProperty]) == 0 ){
429
+ return true ;
430
+ }
431
+
432
+ return false ;
433
+ }
434
+
435
+ // ---------------------------------------------------------------------
436
+
437
+ JSONVar JSONVar::getPropertyWithValue (const String& key, String& value, String child = " " ) const {
438
+ return getPropertyWithValue (key..c_str (), value.c_str (), child.c_str ());
439
+ }
440
+
441
+ // ---------------------------------------------------------------------
442
+
443
+ JSONVar JSONVar::getPropertyWithValue (const char * key, const char * value, const char * child = ' ' ) const {
444
+ if (this .hasOwnPropertyEqualTo (key, value)){
445
+ if (source.hasOwnProperty (childName)){
446
+ return source[childName];
447
+ }
448
+ else {
449
+ return source;
450
+ }
451
+ }
452
+
453
+ if (JSON.typeof_ (source) == " array" ){
454
+ for (int i = 0 ; i < source.length (); ++i) {
455
+ if (_hasMatch (source[i], sourceProperty, targetValue)){
456
+ if (source[i].hasOwnProperty (childName)){
457
+ return source[i][childName];
458
+ }
459
+ else {
460
+ return source[i];
461
+ }
462
+ }
463
+ }
464
+ }
465
+
466
+ return null;
467
+ }
468
+
415
469
JSONVar undefined;
0 commit comments