0

我得到一个 Web 服务响应,它是一个字典数组。每个字典都有其值本身是另一个字典的对象。我需要在此响应中实现搜索,例如,如果我输入“技术”并进行搜索,我应该从具有“该字典中任何位置的技术”的数组中获取那些字典, 有没有办法解决

     {
         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";
}
4

1 回答 1

1

这是第一种方法

    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
            }

        }
    }

或者您可以尝试更简单的方法

在 NSDATA 中获取响应

将 NSDATA 隐藏到 NSString

并在 NSSTRING 中搜索 Substring

于 2013-09-13T10:13:14.923 回答