Filtering an NSDictionary within a dictionary with particular text

General Tech Technology & Software 2 years ago

2 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 30 Aug 2022, this text provides information on Technology & Software related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I am getting a web service repsonse that is an array of dictionary. Each dictionary has objects whose values itself is another dictionary.I need to implement the search within this response,like if i enter "technology" and go for search, I should get those dictionary from the array that has "technology anywhere within that dictionary", Is there a solution to sort out

     {
         key1 =         {
    0 =             {
    "id" = 608;
    "b" = "Apple-Iphone";
     };
    1 =             {
    "id" = 609;
    "b" = "Iphone";
    };
    2 =             {
    "id" = 610;
    "b" = "Show Text";
    };

    };
    key2 = "Technology resources";
    "key3" =         {
    0 =             {
    "id" = 1608;
    "b" = "I love reading";
    };
    1 =             {
    "id" = 1609;
    "b" = "I prefer iphone to others";
    };
    2 =             {
                "id" = 1610;
                "b" = "Mobile technology is great.I am happy to a be developer";
            };

        };

        "key4" = "Mobile technology is the fun";
}
profilepic.png
manpreet 2 years ago

 

This is First Method

    NSMutableDictionary *dict;
    NSArray *allKeys = [dict allKeys];
    for (NSString  *key in allKeys)
    {
        NSDictionary *innerDict = [dict objectForKey:key];

        NSArray *allInnerKeys = [innerDict allKeys];
        for (NSString  *innerKey in allInnerKeys)
        {
            NSDictionary *mostInnerDict = [dict objectForKey:innerKey];
            NSString *b = [mostInnerDict objectForKey:b];
            NSString *search = @"Technology";
            NSString *sub = [b substringFromIndex:NSMaxRange([b rangeOfString:search])];
            if(sub)
            {
                // ADD mostInnerDict Object to your Results Array
            }

        }
    }

Or You can Try The Simpler Method

Get Response in NSDATA

Covert NSDATA To NSString

and search in NSSTRING for Substring


2 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.