iOS从JSON而不是数组自动完成

iOS从JSON而不是数组自动完成,ios,json,autocomplete,Ios,Json,Autocomplete,我想用tableView制作一个自动完成,因为我有以下功能: -(AutocompletionTableView *)autoCompleter { if (!_autoCompleter) { NSMutableDictionary *options = [NSMutableDictionary dictionaryWithCapacity:2]; [options setValue:[NSNumber numberWithBool:YES] f

我想用tableView制作一个自动完成,因为我有以下功能:

-(AutocompletionTableView *)autoCompleter
{
    if (!_autoCompleter)
    {
        NSMutableDictionary *options = [NSMutableDictionary dictionaryWithCapacity:2];
        [options setValue:[NSNumber numberWithBool:YES] forKey:ACOCaseSensitive];
        [options setValue:nil forKey:ACOUseSourceFont];  

        _autoCompleter = [[AutocompletionTableView alloc] initWithTextField:self.textField inViewController:self withOptions:options];
        _autoCompleter.autoCompleteDelegate = self;
        _autoCompleter.suggestionsDictionary = [NSArray arrayWithObjects:@"hostel",@"caret",@"carrot",@"house",@"horse", nil];
    }

    return _autoCompleter;
}
问题是: 我希望从远程JSON文件自动完成,而不是从数组自动完成


你知道我怎么能做这样的事吗?代码片段将非常有用,因为我是iOS开发的新手。

使用NSURLConnection向服务器发出请求后,您应该会收到包含以下数据的NSData:

["hostel","caret","carrot","house","horse"]
此NSData如下所示:

NSString* data = @"[\"hostel\",\"caret\",\"carrot\",\"house\",\"horse\"]";
NSData* dataReceived = [data dataUsingEncoding:NSUTF8StringEncoding];
NSError *jsonError = nil;
NSArray *responseDictionary = [NSJSONSerialization JSONObjectWithData:dataReceived options:0 error:&jsonError];
if(jsonError == nil)
{
    _autoCompleter.suggestionsDictionary = responseArray;
}
因此,要将其转换为数组,可以调用NSJSONSerialization,如下所示:

NSString* data = @"[\"hostel\",\"caret\",\"carrot\",\"house\",\"horse\"]";
NSData* dataReceived = [data dataUsingEncoding:NSUTF8StringEncoding];
NSError *jsonError = nil;
NSArray *responseDictionary = [NSJSONSerialization JSONObjectWithData:dataReceived options:0 error:&jsonError];
if(jsonError == nil)
{
    _autoCompleter.suggestionsDictionary = responseArray;
}

下载JSON并从中提取数组。。。具体是什么问题?正在下载反序列化?在我的例子中,下载和反序列化。好的,从下载和研究开始。NSData可以做到这一点,但不是很好。网络连接更好。然后是NSJSONSerialization。如果有问题,请尝试一下,然后显示代码。