General Tech Technology & Software . 1 year ago

Filtering an NSDictionary within a dictionary with particular text

Filtering an NSDictionary within a dictionary with particular text

2 views   2   0 likes   0 shares Tuteehub forum manpreet 2 answers
tuteehub_quiz
Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

profilepic.png

Tuteehub forum answer Answers (2)


profilepic.png
manpreet Tuteehub forum best answer Best Answer 1 year 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";
}
2 views   0 shares
profilepic.png
manpreet 1 year 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

Related Tags

AskAnything Ask Anything

Ask Me Anything

ask me anything tuteehub

Hello! How can I assist you today?
Whether you have questions, need information, or just want to chat, feel free to let me know